comparison imagej2_find_maxima_jython_script.py @ 2:666af1279007 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:54:34 +0000
parents 1a7c29d5fc11
children 69e28b06e027
comparison
equal deleted inserted replaced
1:1a7c29d5fc11 2:666af1279007
6 6
7 # Fiji Jython interpreter implements Python 2.5 which does not 7 # Fiji Jython interpreter implements Python 2.5 which does not
8 # provide support for argparse. 8 # provide support for argparse.
9 error_log = sys.argv[-10] 9 error_log = sys.argv[-10]
10 input_file = sys.argv[-9] 10 input_file = sys.argv[-9]
11 scale_when_converting = sys.argv[-8] == 'yes' 11 scale_when_converting = sys.argv[-8] == "yes"
12 weighted_rgb_conversions = sys.argv[-7] == 'yes' 12 weighted_rgb_conversions = sys.argv[-7] == "yes"
13 noise_tolerance = int(sys.argv[-6]) 13 noise_tolerance = int(sys.argv[-6])
14 output_type = sys.argv[-5] 14 output_type = sys.argv[-5]
15 exclude_edge_maxima = sys.argv[-4] == 'yes' 15 exclude_edge_maxima = sys.argv[-4] == "yes"
16 light_background = sys.argv[-3] 16 light_background = sys.argv[-3]
17 tmp_output_path = sys.argv[-2] 17 tmp_output_path = sys.argv[-2]
18 output_datatype = sys.argv[-1] 18 output_datatype = sys.argv[-1]
19 19
20 # Open the input image file. 20 # Open the input image file.
34 options.append("scale") 34 options.append("scale")
35 if weighted_rgb_conversions: 35 if weighted_rgb_conversions:
36 options.append("weighted") 36 options.append("weighted")
37 # Perform conversion - must happen even if no options are set. 37 # Perform conversion - must happen even if no options are set.
38 IJ.run(input_image_plus_copy, "Conversions...", "%s" % " ".join(options)) 38 IJ.run(input_image_plus_copy, "Conversions...", "%s" % " ".join(options))
39 if output_type in ['List', 'Count']: 39 if output_type in ["List", "Count"]:
40 # W're generating a tabular file for the output. 40 # W're generating a tabular file for the output.
41 # Set the Find Maxima options. 41 # Set the Find Maxima options.
42 options = ['noise=%d' % noise_tolerance] 42 options = ["noise=%d" % noise_tolerance]
43 if output_type.find('_') > 0: 43 if output_type.find("_") > 0:
44 output_type_str = 'output=[%s]' % output_type.replace('_', ' ') 44 output_type_str = "output=[%s]" % output_type.replace("_", " ")
45 else: 45 else:
46 output_type_str = 'output=%s' % output_type 46 output_type_str = "output=%s" % output_type
47 options.append(output_type_str) 47 options.append(output_type_str)
48 if exclude_edge_maxima: 48 if exclude_edge_maxima:
49 options.append('exclude') 49 options.append("exclude")
50 if light_background: 50 if light_background:
51 options.append('light') 51 options.append("light")
52 # Run the command. 52 # Run the command.
53 IJ.run(input_image_plus_copy, "Find Maxima...", "%s" % " ".join(options)) 53 IJ.run(input_image_plus_copy, "Find Maxima...", "%s" % " ".join(options))
54 results_table = analyzer.getResultsTable() 54 results_table = analyzer.getResultsTable()
55 results_table.saveAs(tmp_output_path) 55 results_table.saveAs(tmp_output_path)
56 else: 56 else:
58 # LIMITATIONS: With output_type=Segmented_Particles 58 # LIMITATIONS: With output_type=Segmented_Particles
59 # (watershed segmentation), some segmentation lines 59 # (watershed segmentation), some segmentation lines
60 # may be improperly placed if local maxima are suppressed 60 # may be improperly placed if local maxima are suppressed
61 # by the tolerance. 61 # by the tolerance.
62 mf = MaximumFinder() 62 mf = MaximumFinder()
63 if output_type == 'Single_Points': 63 if output_type == "Single_Points":
64 output_type_param = mf.SINGLE_POINTS 64 output_type_param = mf.SINGLE_POINTS
65 elif output_type == 'Maxima_Within_Tolerance': 65 elif output_type == "Maxima_Within_Tolerance":
66 output_type_param = mf.IN_TOLERANCE 66 output_type_param = mf.IN_TOLERANCE
67 elif output_type == 'Segmented_Particles': 67 elif output_type == "Segmented_Particles":
68 output_type_param = mf.SEGMENTED 68 output_type_param = mf.SEGMENTED
69 elif output_type == 'List': 69 elif output_type == "List":
70 output_type_param = mf.LIST 70 output_type_param = mf.LIST
71 elif output_type == 'Count': 71 elif output_type == "Count":
72 output_type_param = mf.COUNT 72 output_type_param = mf.COUNT
73 # Get a new byteProcessor with a normal (uninverted) LUT where 73 # Get a new byteProcessor with a normal (uninverted) LUT where
74 # the marked points are set to 255 (Background 0). Pixels outside 74 # the marked points are set to 255 (Background 0). Pixels outside
75 # of the roi of the input image_processor_copy are not set. No 75 # of the roi of the input image_processor_copy are not set. No
76 # output image is created for output types POINT_SELECTION, LIST 76 # output image is created for output types POINT_SELECTION, LIST
77 # and COUNT. In these cases findMaxima returns null. 77 # and COUNT. In these cases findMaxima returns null.
78 byte_processor = mf.findMaxima(image_processor_copy, 78 byte_processor = mf.findMaxima(
79 noise_tolerance, 79 image_processor_copy,
80 ImageProcessor.NO_THRESHOLD, 80 noise_tolerance,
81 output_type_param, 81 ImageProcessor.NO_THRESHOLD,
82 exclude_edge_maxima, 82 output_type_param,
83 False) 83 exclude_edge_maxima,
84 False,
85 )
84 # Invert the image or ROI. 86 # Invert the image or ROI.
85 byte_processor.invert() 87 byte_processor.invert()
86 if output_type == 'Segmented_Particles' and not light_background: 88 if output_type == "Segmented_Particles" and not light_background:
87 # Invert the values in this image's LUT (indexed color model). 89 # Invert the values in this image's LUT (indexed color model).
88 byte_processor.invertLut() 90 byte_processor.invertLut()
89 image_plus = ImagePlus("output", byte_processor) 91 image_plus = ImagePlus("output", byte_processor)
90 IJ.saveAs(image_plus, output_datatype, tmp_output_path) 92 IJ.saveAs(image_plus, output_datatype, tmp_output_path)