comparison imagej2_watershed_binary_jython_script.py @ 1:3272e0439968 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:52:29 +0000
parents bb84f130a4e1
children bdee06a1bcfa
comparison
equal deleted inserted replaced
0:bb84f130a4e1 1:3272e0439968
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[ -5 ] 7 error_log = sys.argv[-5]
8 input = sys.argv[ -4 ] 8 input = sys.argv[-4]
9 black_background = jython_utils.asbool( sys.argv[ -3 ] ) 9 black_background = sys.argv[-3] == 'yes'
10 tmp_output_path = sys.argv[ -2 ] 10 tmp_output_path = sys.argv[-2]
11 output_datatype = sys.argv[ -1 ] 11 output_datatype = sys.argv[-1]
12 12
13 # Open the input image file. 13 # Open the input image file.
14 input_image_plus = IJ.openImage( input ) 14 input_image_plus = IJ.openImage(input)
15 15
16 # Create a copy of the image. 16 # Create a copy of the image.
17 input_image_plus_copy = input_image_plus.duplicate() 17 input_image_plus_copy = input_image_plus.duplicate()
18 image_processor_copy = input_image_plus_copy.getProcessor() 18 image_processor_copy = input_image_plus_copy.getProcessor()
19 19
20 try: 20 # Set binary options.
21 # Set binary options. 21 options = ['edm=Overwrite', 'iterations=1', 'count=1']
22 options = jython_utils.get_binary_options( black_background=black_background ) 22 if (black_background):
23 IJ.run( input_image_plus_copy, "Options...", options ) 23 options.append('black')
24 options = " ".join(options)
25 IJ.run(input_image_plus_copy, "Options...", options)
24 26
25 # Convert image to binary if necessary. 27 # Convert image to binary if necessary.
26 if not image_processor_copy.isBinary(): 28 if not image_processor_copy.isBinary():
27 # Convert the image to binary grayscale. 29 # Convert the image to binary grayscale.
28 IJ.run( input_image_plus_copy, "Make Binary", "" ) 30 IJ.run(input_image_plus_copy, "Make Binary", "")
29 31
30 # Run the command. 32 # Run the command.
31 IJ.run( input_image_plus_copy, "Watershed", "" ) 33 IJ.run(input_image_plus_copy, "Watershed", "")
32 34
33 # Save the ImagePlus object as a new image. 35 # Save the ImagePlus object as a new image.
34 IJ.saveAs( input_image_plus_copy, output_datatype, tmp_output_path ) 36 IJ.saveAs(input_image_plus_copy, output_datatype, tmp_output_path)
35 except Exception, e:
36 jython_utils.handle_error( error_log, str( e ) )