Skip to content

Commit 6a566d8

Browse files
authored
Fix the predict module on Mac (#225)
* Fix the predict module on Mac * no ubyte
1 parent 02ca542 commit 6a566d8

File tree

1 file changed

+7
-35
lines changed

1 file changed

+7
-35
lines changed

active_plugins/predict.py

Lines changed: 7 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -35,37 +35,6 @@
3535
of the channels in **ColorToGray** is the same as the order of the
3636
labels within the ilastik project.
3737
38-
CellProfiler automatically scales grayscale and color images to the
39-
[0.0, 1.0] range on load. Your ilastik classifier should be trained on
40-
images with the same scale as the prediction images. You can ensure
41-
consistent scales by:
42-
43-
- using **ImageMath** to convert the images loaded by CellProfiler back
44-
to their original scale. Use these settings to rescale an image:
45-
46-
- **Operation**: *None*
47-
- **Multiply the first image by**: *RESCALE_VALUE*
48-
- **Set values greater than 1 equal to 1?**: *No*
49-
50-
where *RESCALE_VALUE* is determined by your image data and the value
51-
of *Set intensity range from* in **NamesAndTypes**. For example, the
52-
*RESCALE_VALUE* for 32-bit images rescaled by "*Image bit-depth*" is
53-
65535 (the maximum value allowed by this data type). Please refer to
54-
the help for the setting *Set intensity range from* in
55-
**NamesAndTypes** for more information.
56-
57-
This option is best when your training and prediction images do not
58-
require any preprocessing by CellProfiler.
59-
60-
- preprocessing any training images with CellProfiler (e.g.,
61-
**RescaleIntensity**) and applying the same pre-processing steps to
62-
your analysis pipeline. You can use **SaveImages** to export training
63-
images as 32-bit TIFFs.
64-
65-
This option requires two CellProfiler pipelines, but is effective
66-
when your training and prediction images require preprocessing by
67-
CellProfiler.
68-
6938
Additionally, please ensure CellProfiler is configured to load images in
7039
the same format as ilastik. For example, if your ilastik classifier is
7140
trained on RGB images, use **NamesAndTypes** to load images as RGB by
@@ -139,13 +108,19 @@ def run(self, workspace):
139108
image = workspace.image_set.get_image(self.x_name.value)
140109

141110
x_data = image.pixel_data
111+
x_data = x_data*image.scale
142112

143113
fin = tempfile.NamedTemporaryFile(suffix=".h5", delete=False)
144114

145115
fout = tempfile.NamedTemporaryFile(suffix=".h5", delete=False)
146116

117+
if self.executable.value[-4:] == ".app":
118+
executable = os.path.join(self.executable.value, "Contents/MacOS/ilastik")
119+
else:
120+
executable = self.executable.value
121+
147122
cmd = [
148-
self.executable.value,
123+
executable,
149124
"--headless",
150125
"--project",
151126
self.project_file.value,
@@ -156,9 +131,6 @@ def run(self, workspace):
156131
if self.project_type.value in ["Pixel Classification"]:
157132
cmd += ["--export_source", "Probabilities"]
158133
elif self.project_type.value in ["Autocontext (2-stage)"]:
159-
x_data = skimage.img_as_ubyte(
160-
x_data
161-
) # ilastik requires UINT8. Might be relaxed in future.
162134

163135
cmd += ["--export_source", "probabilities stage 2"]
164136
# cmd += ["--export_source", "probabilities all stages"]

0 commit comments

Comments
 (0)