Skip to content

Commit 30e13c7

Browse files
committed
Updated the app to resolve PIL Image issue running in MAP container
Signed-off-by: M Q <mingmelvinq@nvidia.com>
1 parent 78d58ff commit 30e13c7

File tree

3 files changed

+37
-11
lines changed

3 files changed

+37
-11
lines changed

examples/apps/simple_imaging_app/gaussian_operator.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ def setup(self, spec: OperatorSpec):
5858
spec.param("channel_axis", 2)
5959

6060
def compute(self, op_input, op_output, context):
61+
import numpy as np
6162
from skimage.filters import gaussian
6263
from skimage.io import imsave
6364

@@ -67,6 +68,13 @@ def compute(self, op_input, op_output, context):
6768
data_in = op_input.receive("in1")
6869
data_out = gaussian(data_in, sigma=self.sigma_default, channel_axis=self.channel_axis)
6970

71+
# Make sure the data type is what PIL Image can support, as the imsave function calls PIL Image fromarray()
72+
# Some details can be found at https://stackoverflow.com/questions/55319949/pil-typeerror-cannot-handle-this-data-type
73+
print(f"Data type of output: {type(data_out)!r}, max = {np.max(data_out)!r}")
74+
if np.max(data_out) <= 1:
75+
data_out = (data_out*255).astype(np.uint8)
76+
print(f"Data type of output post conversion: {type(data_out)!r}, max = {np.max(data_out)!r}")
77+
7078
# For now, use attribute of self to find the output path.
7179
self.output_folder.mkdir(parents=True, exist_ok=True)
7280
output_path = self.output_folder / "final_output.png"

notebooks/tutorials/01_simple_app.ipynb

Lines changed: 28 additions & 10 deletions
Large diffs are not rendered by default.

requirements-examples.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ pydicom>=2.3.0
33
PyPDF2>=2.11.1
44
highdicom>=0.18.2
55
SimpleITK>=2.0.0
6-
Pillow>=8.0.0
6+
Pillow>=8.4.0
77
numpy-stl>=2.12.0
88
trimesh>=3.8.11
99
nibabel>=3.2.1

0 commit comments

Comments
 (0)