comparison imagej2_adjust_threshold_binary_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
5 # Fiji Jython interpreter implements Python 2.5 which does not
6 # provide support for argparse.
7 error_log = sys.argv[ -10 ]
8 input = sys.argv[ -9 ]
9 threshold_min = float( sys.argv[ -8 ] )
10 threshold_max = float( sys.argv[ -7 ] )
11 method = sys.argv[ -6 ]
12 display = sys.argv[ -5 ]
13 black_background = jython_utils.asbool( sys.argv[ -4 ] )
14 # TODO: this is not being used.
15 stack_histogram = 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 # Convert image to binary if necessary.
28 if not image_processor_copy.isBinary():
29 # Convert the image to binary grayscale.
30 IJ.run( input_image_plus_copy, "Make Binary","iterations=1 count=1 edm=Overwrite do=Nothing" )
31 # Set the options.
32 if black_background:
33 method_str = "%s dark" % method
34 else:
35 method_str = method
36 IJ.setAutoThreshold( input_image_plus_copy, method_str )
37 if display == "red":
38 display_mode = "Red"
39 elif display == "bw":
40 display_mode = "Black & White"
41 elif display == "over_under":
42 display_mode = "Over/Under"
43 IJ.setThreshold( input_image_plus_copy, threshold_min, threshold_max, display_mode )
44 # Run the command.
45 IJ.run( input_image_plus_copy, "threshold", "" )
46 # Save the ImagePlus object as a new image.
47 IJ.saveAs( input_image_plus_copy, output_datatype, tmp_output_path )
48 except Exception, e:
49 jython_utils.handle_error( error_log, str( e ) )