comparison imagej2_adjust_threshold_binary_jython_script.py @ 1:4c43ba752312 draft

"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 2afb24f3c81d625312186750a714d702363012b5"
author imgteam
date Mon, 28 Sep 2020 16:38:24 +0000
parents a84f2cbf091b
children 49e29abe0fce
comparison
equal deleted inserted replaced
0:a84f2cbf091b 1:4c43ba752312
1 import jython_utils
2 import sys 1 import sys
2
3 from ij import IJ 3 from ij import IJ
4 4
5 # Fiji Jython interpreter implements Python 2.5 which does not 5 # Fiji Jython interpreter implements Python 2.5 which does not
6 # provide support for argparse. 6 # provide support for argparse.
7 error_log = sys.argv[ -10 ] 7 error_log = sys.argv[-10]
8 input = sys.argv[ -9 ] 8 input_file = sys.argv[-9]
9 threshold_min = float( sys.argv[ -8 ] ) 9 threshold_min = float(sys.argv[-8])
10 threshold_max = float( sys.argv[ -7 ] ) 10 threshold_max = float(sys.argv[-7])
11 method = sys.argv[ -6 ] 11 method = sys.argv[-6]
12 display = sys.argv[ -5 ] 12 display = sys.argv[-5]
13 black_background = jython_utils.asbool( sys.argv[ -4 ] ) 13 black_background = sys.argv[-4] == "yes"
14 # TODO: this is not being used. 14 # TODO: this is not being used.
15 stack_histogram = jython_utils.asbool( sys.argv[ -3 ] ) 15 stack_histogram = sys.argv[-3] == "yes"
16 tmp_output_path = sys.argv[ -2 ] 16 output_filename = sys.argv[-2]
17 output_datatype = sys.argv[ -1 ] 17 output_datatype = sys.argv[-1]
18 18
19 # Open the input image file. 19 # Open the input image file.
20 input_image_plus = IJ.openImage( input ) 20 input_image_plus = IJ.openImage(input_file)
21 21
22 # Create a copy of the image. 22 # Create a copy of the image.
23 input_image_plus_copy = input_image_plus.duplicate() 23 input_image_plus_copy = input_image_plus.duplicate()
24 image_processor_copy = input_image_plus_copy.getProcessor() 24 image_processor_copy = input_image_plus_copy.getProcessor()
25 25
26 try: 26 # Convert image to binary if necessary.
27 # Convert image to binary if necessary. 27 if not image_processor_copy.isBinary():
28 if not image_processor_copy.isBinary(): 28 # Convert the image to binary grayscale.
29 # Convert the image to binary grayscale. 29 IJ.run(input_image_plus_copy, "Make Binary", "iterations=1 count=1 edm=Overwrite do=Nothing")
30 IJ.run( input_image_plus_copy, "Make Binary","iterations=1 count=1 edm=Overwrite do=Nothing" ) 30 # Set the options.
31 # Set the options. 31 if black_background:
32 if black_background: 32 method_str = "%s dark" % method
33 method_str = "%s dark" % method 33 else:
34 else: 34 method_str = method
35 method_str = method 35 IJ.setAutoThreshold(input_image_plus_copy, method_str)
36 IJ.setAutoThreshold( input_image_plus_copy, method_str ) 36 if display == "red":
37 if display == "red": 37 display_mode = "Red"
38 display_mode = "Red" 38 elif display == "bw":
39 elif display == "bw": 39 display_mode = "Black & White"
40 display_mode = "Black & White" 40 elif display == "over_under":
41 elif display == "over_under": 41 display_mode = "Over/Under"
42 display_mode = "Over/Under" 42 IJ.setThreshold(input_image_plus_copy, threshold_min, threshold_max, display_mode)
43 IJ.setThreshold( input_image_plus_copy, threshold_min, threshold_max, display_mode ) 43 # Run the command.
44 # Run the command. 44 IJ.run(input_image_plus_copy, "threshold", "")
45 IJ.run( input_image_plus_copy, "threshold", "" ) 45 # Save the ImagePlus object as a new image.
46 # Save the ImagePlus object as a new image. 46 IJ.saveAs(input_image_plus_copy, output_datatype, output_filename)
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 ) )