|
9 | 9 | from ..log import LOG as log |
10 | 10 |
|
11 | 11 |
|
| 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 | + |
12 | 43 | def apply_filter(imp, filter_method, filter_radius, do_3d=False): |
13 | 44 | """Make a specific filter followed by a threshold method of choice. |
14 | 45 |
|
@@ -47,16 +78,7 @@ def apply_filter(imp, filter_method, filter_radius, do_3d=False): |
47 | 78 | "filter_method must be one of: Median, Mean, Gaussian Blur, Minimum, Maximum" |
48 | 79 | ) |
49 | 80 |
|
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) |
60 | 82 |
|
61 | 83 | log.debug("Filter: <%s> with options <%s>" % (filter, options)) |
62 | 84 |
|
@@ -156,18 +178,14 @@ def apply_threshold(imp, threshold_method, do_3d=True): |
156 | 178 |
|
157 | 179 | imageplus = imp.duplicate() |
158 | 180 |
|
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 |
161 | 183 | ) |
162 | 184 |
|
163 | 185 | log.debug("Auto threshold options: %s" % auto_threshold_options) |
164 | 186 |
|
165 | 187 | IJ.setAutoThreshold(imageplus, auto_threshold_options) |
166 | 188 |
|
167 | | - convert_to_binary_options = ( |
168 | | - "method=" + threshold_method + " " + "background=Dark" + " " + "black" |
169 | | - ) |
170 | | - |
171 | 189 | log.debug("Convert to binary options: %s" % convert_to_binary_options) |
172 | 190 |
|
173 | 191 | IJ.run(imageplus, "Convert to Mask", convert_to_binary_options) |
|
0 commit comments