comparison imagej2_math_jython_script.py @ 2:49e29abe0fce draft

planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 57a0433defa3cbc37ab34fbb0ebcfaeb680db8d5
author imgteam
date Sun, 05 Nov 2023 10:49:30 +0000
parents 4c43ba752312
children 418b1fa32b83
comparison
equal deleted inserted replaced
1:4c43ba752312 2:49e29abe0fce
6 # provide support for argparse. 6 # provide support for argparse.
7 error_log = sys.argv[-8] 7 error_log = sys.argv[-8]
8 input_file = sys.argv[-7] 8 input_file = sys.argv[-7]
9 operation = sys.argv[-6] 9 operation = sys.argv[-6]
10 expression = sys.argv[-5] 10 expression = sys.argv[-5]
11 if sys.argv[-4] in [None, 'None']: 11 if sys.argv[-4] in [None, "None"]:
12 bin_constant = None 12 bin_constant = None
13 else: 13 else:
14 bin_constant = int(sys.argv[-4]) 14 bin_constant = int(sys.argv[-4])
15 if sys.argv[-3] in [None, 'None']: 15 if sys.argv[-3] in [None, "None"]:
16 float_constant = None 16 float_constant = None
17 else: 17 else:
18 float_constant = float(sys.argv[-3]) 18 float_constant = float(sys.argv[-3])
19 tmp_output_path = sys.argv[-2] 19 tmp_output_path = sys.argv[-2]
20 output_datatype = sys.argv[-1] 20 output_datatype = sys.argv[-1]
34 # Create a copy of the image. 34 # Create a copy of the image.
35 input_image_plus_copy = input_image_plus.duplicate() 35 input_image_plus_copy = input_image_plus.duplicate()
36 image_processor_copy = input_image_plus_copy.getProcessor() 36 image_processor_copy = input_image_plus_copy.getProcessor()
37 bit_depth = image_processor_copy.getBitDepth() 37 bit_depth = image_processor_copy.getBitDepth()
38 38
39 if operation.find('_') > 0: 39 if operation.find("_") > 0:
40 # Square_Root. 40 # Square_Root.
41 new_operation = operation.replace('_', ' ') 41 new_operation = operation.replace("_", " ")
42 elif operation in ['Square', 'Log', 'Exp', 'Abs', 'Reciprocal']: 42 elif operation in ["Square", "Log", "Exp", "Abs", "Reciprocal"]:
43 # Unfortunately some ImageJ commands require a "..." ending 43 # Unfortunately some ImageJ commands require a "..." ending
44 # while others do not. There seems to be no pattern. 44 # while others do not. There seems to be no pattern.
45 new_operation = '%s' % operation 45 new_operation = "%s" % operation
46 else: 46 else:
47 new_operation = '%s...' % operation 47 new_operation = "%s..." % operation
48 48
49 if operation == 'Macro': 49 if operation == "Macro":
50 # Apply the macro code to the image via a call to it's 50 # Apply the macro code to the image via a call to it's
51 # ImageProcessor since this option does not work using 51 # ImageProcessor since this option does not work using
52 # the IJ.run() method. 52 # the IJ.run() method.
53 new_expression = expression.lstrip('"').rstrip('"') 53 new_expression = expression.lstrip('"').rstrip('"')
54 options = 'code=%s' % new_expression 54 options = "code=%s" % new_expression
55 image_processor_copy.applyMacro(new_expression) 55 image_processor_copy.applyMacro(new_expression)
56 elif operation == 'Min': 56 elif operation == "Min":
57 # Min does not work without using the ImageProcessor. 57 # Min does not work without using the ImageProcessor.
58 image_processor_copy.min(float_constant) 58 image_processor_copy.min(float_constant)
59 elif operation == 'Max': 59 elif operation == "Max":
60 # Max does not work without using the ImageProcessor. 60 # Max does not work without using the ImageProcessor.
61 image_processor_copy.max(float_constant) 61 image_processor_copy.max(float_constant)
62 elif operation == 'Abs': 62 elif operation == "Abs":
63 if bit_depth not in [16, 32]: 63 if bit_depth not in [16, 32]:
64 # Convert the image to 32-bit. 64 # Convert the image to 32-bit.
65 IJ.run(input_image_plus_copy, "32-bit", "") 65 IJ.run(input_image_plus_copy, "32-bit", "")
66 IJ.run(input_image_plus_copy, new_operation, "") 66 IJ.run(input_image_plus_copy, new_operation, "")
67 elif operation == 'Reciprocal': 67 elif operation == "Reciprocal":
68 if bit_depth != 32: 68 if bit_depth != 32:
69 # Convert the image to 32 bit. 69 # Convert the image to 32 bit.
70 IJ.run(input_image_plus_copy, "32-bit", "") 70 IJ.run(input_image_plus_copy, "32-bit", "")
71 IJ.run(input_image_plus_copy, new_operation, "") 71 IJ.run(input_image_plus_copy, new_operation, "")
72 else: 72 else:
73 if operation in ['AND', 'OR', 'XOR']: 73 if operation in ["AND", "OR", "XOR"]:
74 # Value is a binary number. 74 # Value is a binary number.
75 options = 'value=%d' % bin_constant 75 options = "value=%d" % bin_constant
76 elif operation in ['Log', 'Exp', 'Square', 'Square_Root']: 76 elif operation in ["Log", "Exp", "Square", "Square_Root"]:
77 # No constant value. 77 # No constant value.
78 options = '' 78 options = ""
79 else: 79 else:
80 # Value is a floating point number. 80 # Value is a floating point number.
81 options = 'value=%.3f' % float_constant 81 options = "value=%.3f" % float_constant
82 IJ.run(input_image_plus_copy, "%s" % new_operation, "%s" % options) 82 IJ.run(input_image_plus_copy, "%s" % new_operation, "%s" % options)
83 # Save the ImagePlus object as a new image. 83 # Save the ImagePlus object as a new image.
84 IJ.saveAs(input_image_plus_copy, output_datatype, tmp_output_path) 84 IJ.saveAs(input_image_plus_copy, output_datatype, tmp_output_path)