comparison jython_script.py @ 1:d26f11339f08 draft

planemo upload commit 18df9e67efd4adafcde4eb9b62cd815e4afe9733-dirty
author iuc
date Wed, 26 Aug 2015 14:37:41 -0400
parents 66d9e595dff2
children
comparison
equal deleted inserted replaced
0:66d9e595dff2 1:d26f11339f08
1 import jython_utils 1 import jython_utils
2 import sys 2 import sys
3 from ij import IJ 3 from ij import IJ
4 from ij import ImagePlus
5 4
6 # Fiji Jython interpreter implements Python 2.5 which does not 5 # Fiji Jython interpreter implements Python 2.5 which does not
7 # provide support for argparse. 6 # provide support for argparse.
8 error_log = sys.argv[ -8 ] 7 error_log = sys.argv[ -8 ]
9 input = sys.argv[ -7 ] 8 input = sys.argv[ -7 ]
10 iterations = sys.argv[ -6 ] 9 iterations = int( sys.argv[ -6 ] )
11 count = sys.argv[ -5 ] 10 count = int( sys.argv[ -5 ] )
12 black_background = sys.argv[ -4 ] 11 black_background = jython_utils.asbool( sys.argv[ -4 ] )
13 pad_edges_when_eroding = sys.argv[ -3 ] 12 pad_edges_when_eroding = jython_utils.asbool( sys.argv[ -3 ] )
14 tmp_output_path = sys.argv[ -2 ] 13 tmp_output_path = sys.argv[ -2 ]
15 output_datatype = sys.argv[ -1 ] 14 output_datatype = sys.argv[ -1 ]
16 15
17 # Open the input image file. 16 # Open the input image file.
18 input_image_plus = IJ.openImage( input ) 17 input_image_plus = IJ.openImage( input )
19 bit_depth = input_image_plus.getBitDepth()
20 image_type = input_image_plus.getType()
21 18
22 # Create a copy of the image. 19 # Create a copy of the image.
23 input_image_plus_copy = input_image_plus.createImagePlus() 20 input_image_plus_copy = input_image_plus.duplicate()
24 image_processor_copy = input_image_plus.getProcessor().duplicate() 21 image_processor_copy = input_image_plus_copy.getProcessor()
25 input_image_plus_copy.setProcessor( "iCopy", image_processor_copy )
26 22
27 try: 23 try:
28 options = [ "iterations=&iterations" "count=&count" ] 24 # Set binary options.
29 if black_background == "yes": 25 options = jython_utils.get_binary_options( black_background=black_background,
30 options.append( "black" ) 26 iterations=iterations,
31 if pad_edges_when_eroding == "yes": 27 count=count,
32 options.append( "pad" ) 28 pad_edges_when_eroding=pad_edges_when_eroding )
33 # The following have no affect within this tool, but are necessary. 29 IJ.run( input_image_plus_copy, "Options...", options )
34 options.append( "edm=Overwrite" ) 30
35 options.append( "do=Nothing" )
36 # Run the command. 31 # Run the command.
37 IJ.run( input_image_plus_copy, "Make Binary", " ".join( options ) ) 32 IJ.run( input_image_plus_copy, "Make Binary", "" )
33
38 # Save the ImagePlus object as a new image. 34 # Save the ImagePlus object as a new image.
39 IJ.saveAs( input_image_plus_copy, output_datatype, tmp_output_path ) 35 IJ.saveAs( input_image_plus_copy, output_datatype, tmp_output_path )
40 except Exception, e: 36 except Exception, e:
41 jython_utils.handle_error( error_log, str( e ) ) 37 jython_utils.handle_error( error_log, str( e ) )