comparison imagej2_binary_to_edm_jython_script.py @ 0:f6df6830d5ec draft

"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
author imgteam
date Tue, 17 Sep 2019 16:57:15 -0400
parents
children 768825d9034a
comparison
equal deleted inserted replaced
-1:000000000000 0:f6df6830d5ec
1 import jython_utils
2 import sys
3 from ij import IJ
4 from ij import ImagePlus
5 from ij.plugin.filter import Analyzer
6 from ij.plugin.filter import EDM
7
8 # Fiji Jython interpreter implements Python 2.5 which does not
9 # provide support for argparse.
10 error_log = sys.argv[ -8 ]
11 input = sys.argv[ -7 ]
12 iterations = int( sys.argv[ -6 ] )
13 count = int( sys.argv[ -5 ] )
14 black_background = jython_utils.asbool( sys.argv[ -4 ] )
15 pad_edges_when_eroding = jython_utils.asbool( sys.argv[ -3 ] )
16 tmp_output_path = sys.argv[ -2 ]
17 output_datatype = sys.argv[ -1 ]
18
19 # Open the input image file.
20 input_image_plus = IJ.openImage( input )
21
22 # Create a copy of the image.
23 input_image_plus_copy = input_image_plus.duplicate()
24 image_processor_copy = input_image_plus_copy.getProcessor()
25
26 try:
27 # Set binary options.
28 options = jython_utils.get_binary_options( black_background=black_background,
29 iterations=iterations,
30 count=count,
31 pad_edges_when_eroding=pad_edges_when_eroding )
32 IJ.run( input_image_plus_copy, "Options...", options )
33
34 # Convert image to binary if necessary.
35 if not image_processor_copy.isBinary():
36 # Convert the image to binary grayscale.
37 IJ.run( input_image_plus_copy, "Make Binary", "" )
38
39 # Run the command.
40 IJ.run( input_image_plus_copy, "Distance Map", "" )
41 # Save the ImagePlus object as a new image.
42 IJ.saveAs( input_image_plus_copy, output_datatype, tmp_output_path )
43 except Exception, e:
44 jython_utils.handle_error( error_log, str( e ) )