Skip to content

Commit 4a4a10b

Browse files
author
Laurent Guerard
committed
Add pure helpers for processing options
1 parent 373a05c commit 4a4a10b

1 file changed

Lines changed: 34 additions & 16 deletions

File tree

src/imcflibs/imagej/processing.py

Lines changed: 34 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,37 @@
99
from ..log import LOG as log
1010

1111

12+
def filter_options(filter_method, filter_radius, do_3d=False):
13+
"""Build the ImageJ filter command and options strings."""
14+
15+
if do_3d:
16+
filter_name = filter_method + " 3D..."
17+
else:
18+
filter_name = filter_method + "..."
19+
20+
options = (
21+
"sigma="
22+
if filter_method == "Gaussian Blur"
23+
else "radius=" + str(filter_radius) + " stack"
24+
)
25+
26+
return filter_name, options
27+
28+
29+
def threshold_options(threshold_method, do_3d=True):
30+
"""Build the ImageJ threshold option strings."""
31+
32+
auto_threshold_options = (
33+
threshold_method + " " + "dark" + " " + "stack" if do_3d else ""
34+
)
35+
36+
convert_to_binary_options = (
37+
"method=" + threshold_method + " " + "background=Dark" + " " + "black"
38+
)
39+
40+
return auto_threshold_options, convert_to_binary_options
41+
42+
1243
def apply_filter(imp, filter_method, filter_radius, do_3d=False):
1344
"""Make a specific filter followed by a threshold method of choice.
1445
@@ -47,16 +78,7 @@ def apply_filter(imp, filter_method, filter_radius, do_3d=False):
4778
"filter_method must be one of: Median, Mean, Gaussian Blur, Minimum, Maximum"
4879
)
4980

50-
if do_3d:
51-
filter = filter_method + " 3D..."
52-
else:
53-
filter = filter_method + "..."
54-
55-
options = (
56-
"sigma="
57-
if filter_method == "Gaussian Blur"
58-
else "radius=" + str(filter_radius) + " stack"
59-
)
81+
filter, options = filter_options(filter_method, filter_radius, do_3d=do_3d)
6082

6183
log.debug("Filter: <%s> with options <%s>" % (filter, options))
6284

@@ -156,18 +178,14 @@ def apply_threshold(imp, threshold_method, do_3d=True):
156178

157179
imageplus = imp.duplicate()
158180

159-
auto_threshold_options = (
160-
threshold_method + " " + "dark" + " " + "stack" if do_3d else ""
181+
auto_threshold_options, convert_to_binary_options = threshold_options(
182+
threshold_method, do_3d=do_3d
161183
)
162184

163185
log.debug("Auto threshold options: %s" % auto_threshold_options)
164186

165187
IJ.setAutoThreshold(imageplus, auto_threshold_options)
166188

167-
convert_to_binary_options = (
168-
"method=" + threshold_method + " " + "background=Dark" + " " + "black"
169-
)
170-
171189
log.debug("Convert to binary options: %s" % convert_to_binary_options)
172190

173191
IJ.run(imageplus, "Convert to Mask", convert_to_binary_options)

0 commit comments

Comments
 (0)