comparison jython_script.py @ 1:269923244cc8 draft

planemo upload commit 18df9e67efd4adafcde4eb9b62cd815e4afe9733-dirty
author iuc
date Wed, 26 Aug 2015 14:38:34 -0400
parents 8b787f641b9c
children
comparison
equal deleted inserted replaced
0:8b787f641b9c 1:269923244cc8
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
6 VALID_IMAGE_TYPES = [ ImagePlus.GRAY8 ]
7 4
8 # Fiji Jython interpreter implements Python 2.5 which does not 5 # Fiji Jython interpreter implements Python 2.5 which does not
9 # provide support for argparse. 6 # provide support for argparse.
10 error_log = sys.argv[ -4 ] 7 error_log = sys.argv[ -5 ]
11 input = sys.argv[ -3 ] 8 input = sys.argv[ -4 ]
9 black_background = jython_utils.asbool( sys.argv[ -3 ] )
12 tmp_output_path = sys.argv[ -2 ] 10 tmp_output_path = sys.argv[ -2 ]
13 output_datatype = sys.argv[ -1 ] 11 output_datatype = sys.argv[ -1 ]
14 12
15 # Open the input image file. 13 # Open the input image file.
16 input_image_plus = IJ.openImage( input ) 14 input_image_plus = IJ.openImage( input )
17 bit_depth = input_image_plus.getBitDepth()
18 image_type = input_image_plus.getType()
19 15
20 # Create a copy of the image. 16 # Create a copy of the image.
21 input_image_plus_copy = input_image_plus.createImagePlus() 17 input_image_plus_copy = input_image_plus.duplicate()
22 image_processor_copy = input_image_plus.getProcessor().duplicate() 18 image_processor_copy = input_image_plus_copy.getProcessor()
23 input_image_plus_copy.setProcessor( "iCopy", image_processor_copy )
24 19
25 try: 20 try:
26 if image_type not in VALID_IMAGE_TYPES: 21 # Set binary options.
22 options = jython_utils.get_binary_options( black_background=black_background )
23 IJ.run( input_image_plus_copy, "Options...", options )
24
25 # Convert image to binary if necessary.
26 if not image_processor_copy.isBinary():
27 # Convert the image to binary grayscale. 27 # Convert the image to binary grayscale.
28 IJ.run( input_image_plus_copy, "Make Binary","iterations=1 count=1 edm=Overwrite do=Nothing" ) 28 IJ.run( input_image_plus_copy, "Make Binary", "" )
29
29 # Run the command. 30 # Run the command.
30 IJ.run( input_image_plus_copy, "Skeletonize (2D/3D)", "" ) 31 IJ.run( input_image_plus_copy, "Skeletonize (2D/3D)", "" )
32
31 # Save the ImagePlus object as a new image. 33 # Save the ImagePlus object as a new image.
32 IJ.saveAs( input_image_plus_copy, output_datatype, tmp_output_path ) 34 IJ.saveAs( input_image_plus_copy, output_datatype, tmp_output_path )
33 except Exception, e: 35 except Exception, e:
34 jython_utils.handle_error( error_log, str( e ) ) 36 jython_utils.handle_error( error_log, str( e ) )