Mercurial > repos > bgruening > imagej2_crop
comparison imagej2_adjust_threshold_binary_jython_script.py @ 0:018144807556 draft default tip
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
author | bgruening |
---|---|
date | Tue, 24 Sep 2024 17:12:52 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:018144807556 |
---|---|
1 import sys | |
2 | |
3 from ij import IJ, Prefs | |
4 | |
5 # Fiji Jython interpreter implements Python 2.5 which does not | |
6 # provide support for argparse. | |
7 input_file = sys.argv[-8] | |
8 threshold_min = float(sys.argv[-7]) | |
9 threshold_max = float(sys.argv[-6]) | |
10 method = sys.argv[-5] | |
11 display = sys.argv[-4] | |
12 black_background = sys.argv[-3] == "yes" | |
13 output_filename = sys.argv[-2] | |
14 output_datatype = sys.argv[-1] | |
15 | |
16 # Open the input image file. | |
17 input_image_plus = IJ.openImage(input_file) | |
18 | |
19 # Create a copy of the image. | |
20 input_image_plus_copy = input_image_plus.duplicate() | |
21 | |
22 bit_depth = input_image_plus_copy.getBitDepth() | |
23 | |
24 if black_background: | |
25 Prefs.blackBackground = True | |
26 else: | |
27 Prefs.blackBackground = False | |
28 | |
29 if method != "Manual": | |
30 # Set the options. | |
31 if black_background: | |
32 method_str = "%s dark" % method | |
33 suffix = "black" | |
34 else: | |
35 method_str = method | |
36 suffix = "" | |
37 threshold_min = 1 | |
38 # Set threshold_max based on image bit-depth | |
39 # For 8-bit images, use 255; for 16-bit images, use 65535 | |
40 if bit_depth == 8: | |
41 threshold_max = 255 # Default for 8-bit images | |
42 elif bit_depth == 16: | |
43 threshold_max = 65535 # Default for 16-bit images | |
44 else: | |
45 threshold_max = float('inf') # General fallback if bit depth is unknown | |
46 | |
47 IJ.setAutoThreshold(input_image_plus_copy, method_str) | |
48 IJ.run(input_image_plus_copy, "Convert to Mask", "calculate %s" % suffix) | |
49 if display == "red": | |
50 display_mode = "Red" | |
51 elif display == "bw": | |
52 display_mode = "Black & White" | |
53 elif display == "over_under": | |
54 display_mode = "Over/Under" | |
55 IJ.setThreshold(input_image_plus_copy, threshold_min, threshold_max, display_mode) | |
56 # Save the ImagePlus object as a new image. | |
57 IJ.saveAs(input_image_plus_copy, output_datatype, output_filename) |