comparison imagej2_binary_to_edm_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
4
5 # Fiji Jython interpreter implements Python 2.5 which does not
6 # provide support for argparse.
7 input_file = sys.argv[-7]
8 iterations = int(sys.argv[-6])
9 count = int(sys.argv[-5])
10 black_background = sys.argv[-4] == "yes"
11 pad_edges_when_eroding = sys.argv[-3] == "yes"
12 output_filename = sys.argv[-2]
13 output_datatype = sys.argv[-1]
14
15 # Open the input image file.
16 input_image_plus = IJ.openImage(input_file)
17
18 # Create a copy of the image.
19 input_image_plus_copy = input_image_plus.duplicate()
20 image_processor_copy = input_image_plus_copy.getProcessor()
21
22 # Set binary options.
23 options_list = ["edm=Overwrite", "iterations=%d" % iterations, "count=%d" % count]
24 if black_background:
25 options_list.append("black")
26 if pad_edges_when_eroding:
27 options_list.append("pad")
28 options = " ".join(options_list)
29 IJ.run(input_image_plus_copy, "Options...", options)
30
31 # Convert image to binary if necessary.
32 if not image_processor_copy.isBinary():
33 # Convert the image to binary grayscale.
34 IJ.run(input_image_plus_copy, "Make Binary", "")
35
36 # Run the command.
37 IJ.run(input_image_plus_copy, "Distance Map", "")
38 # Save the ImagePlus object as a new image.
39 IJ.saveAs(input_image_plus_copy, output_datatype, output_filename)