annotate jython_script.py @ 0:8b787f641b9c draft

planemo upload commit 98c34e070343a117019ffd25a3af117808159bf5-dirty
author iuc
date Tue, 04 Aug 2015 13:21:32 -0400
parents
children 269923244cc8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
8b787f641b9c planemo upload commit 98c34e070343a117019ffd25a3af117808159bf5-dirty
iuc
parents:
diff changeset
1 import jython_utils
8b787f641b9c planemo upload commit 98c34e070343a117019ffd25a3af117808159bf5-dirty
iuc
parents:
diff changeset
2 import sys
8b787f641b9c planemo upload commit 98c34e070343a117019ffd25a3af117808159bf5-dirty
iuc
parents:
diff changeset
3 from ij import IJ
8b787f641b9c planemo upload commit 98c34e070343a117019ffd25a3af117808159bf5-dirty
iuc
parents:
diff changeset
4 from ij import ImagePlus
8b787f641b9c planemo upload commit 98c34e070343a117019ffd25a3af117808159bf5-dirty
iuc
parents:
diff changeset
5
8b787f641b9c planemo upload commit 98c34e070343a117019ffd25a3af117808159bf5-dirty
iuc
parents:
diff changeset
6 VALID_IMAGE_TYPES = [ ImagePlus.GRAY8 ]
8b787f641b9c planemo upload commit 98c34e070343a117019ffd25a3af117808159bf5-dirty
iuc
parents:
diff changeset
7
8b787f641b9c planemo upload commit 98c34e070343a117019ffd25a3af117808159bf5-dirty
iuc
parents:
diff changeset
8 # Fiji Jython interpreter implements Python 2.5 which does not
8b787f641b9c planemo upload commit 98c34e070343a117019ffd25a3af117808159bf5-dirty
iuc
parents:
diff changeset
9 # provide support for argparse.
8b787f641b9c planemo upload commit 98c34e070343a117019ffd25a3af117808159bf5-dirty
iuc
parents:
diff changeset
10 error_log = sys.argv[ -4 ]
8b787f641b9c planemo upload commit 98c34e070343a117019ffd25a3af117808159bf5-dirty
iuc
parents:
diff changeset
11 input = sys.argv[ -3 ]
8b787f641b9c planemo upload commit 98c34e070343a117019ffd25a3af117808159bf5-dirty
iuc
parents:
diff changeset
12 tmp_output_path = sys.argv[ -2 ]
8b787f641b9c planemo upload commit 98c34e070343a117019ffd25a3af117808159bf5-dirty
iuc
parents:
diff changeset
13 output_datatype = sys.argv[ -1 ]
8b787f641b9c planemo upload commit 98c34e070343a117019ffd25a3af117808159bf5-dirty
iuc
parents:
diff changeset
14
8b787f641b9c planemo upload commit 98c34e070343a117019ffd25a3af117808159bf5-dirty
iuc
parents:
diff changeset
15 # Open the input image file.
8b787f641b9c planemo upload commit 98c34e070343a117019ffd25a3af117808159bf5-dirty
iuc
parents:
diff changeset
16 input_image_plus = IJ.openImage( input )
8b787f641b9c planemo upload commit 98c34e070343a117019ffd25a3af117808159bf5-dirty
iuc
parents:
diff changeset
17 bit_depth = input_image_plus.getBitDepth()
8b787f641b9c planemo upload commit 98c34e070343a117019ffd25a3af117808159bf5-dirty
iuc
parents:
diff changeset
18 image_type = input_image_plus.getType()
8b787f641b9c planemo upload commit 98c34e070343a117019ffd25a3af117808159bf5-dirty
iuc
parents:
diff changeset
19
8b787f641b9c planemo upload commit 98c34e070343a117019ffd25a3af117808159bf5-dirty
iuc
parents:
diff changeset
20 # Create a copy of the image.
8b787f641b9c planemo upload commit 98c34e070343a117019ffd25a3af117808159bf5-dirty
iuc
parents:
diff changeset
21 input_image_plus_copy = input_image_plus.createImagePlus()
8b787f641b9c planemo upload commit 98c34e070343a117019ffd25a3af117808159bf5-dirty
iuc
parents:
diff changeset
22 image_processor_copy = input_image_plus.getProcessor().duplicate()
8b787f641b9c planemo upload commit 98c34e070343a117019ffd25a3af117808159bf5-dirty
iuc
parents:
diff changeset
23 input_image_plus_copy.setProcessor( "iCopy", image_processor_copy )
8b787f641b9c planemo upload commit 98c34e070343a117019ffd25a3af117808159bf5-dirty
iuc
parents:
diff changeset
24
8b787f641b9c planemo upload commit 98c34e070343a117019ffd25a3af117808159bf5-dirty
iuc
parents:
diff changeset
25 try:
8b787f641b9c planemo upload commit 98c34e070343a117019ffd25a3af117808159bf5-dirty
iuc
parents:
diff changeset
26 if image_type not in VALID_IMAGE_TYPES:
8b787f641b9c planemo upload commit 98c34e070343a117019ffd25a3af117808159bf5-dirty
iuc
parents:
diff changeset
27 # Convert the image to binary grayscale.
8b787f641b9c planemo upload commit 98c34e070343a117019ffd25a3af117808159bf5-dirty
iuc
parents:
diff changeset
28 IJ.run( input_image_plus_copy, "Make Binary","iterations=1 count=1 edm=Overwrite do=Nothing" )
8b787f641b9c planemo upload commit 98c34e070343a117019ffd25a3af117808159bf5-dirty
iuc
parents:
diff changeset
29 # Run the command.
8b787f641b9c planemo upload commit 98c34e070343a117019ffd25a3af117808159bf5-dirty
iuc
parents:
diff changeset
30 IJ.run( input_image_plus_copy, "Skeletonize (2D/3D)", "" )
8b787f641b9c planemo upload commit 98c34e070343a117019ffd25a3af117808159bf5-dirty
iuc
parents:
diff changeset
31 # Save the ImagePlus object as a new image.
8b787f641b9c planemo upload commit 98c34e070343a117019ffd25a3af117808159bf5-dirty
iuc
parents:
diff changeset
32 IJ.saveAs( input_image_plus_copy, output_datatype, tmp_output_path )
8b787f641b9c planemo upload commit 98c34e070343a117019ffd25a3af117808159bf5-dirty
iuc
parents:
diff changeset
33 except Exception, e:
8b787f641b9c planemo upload commit 98c34e070343a117019ffd25a3af117808159bf5-dirty
iuc
parents:
diff changeset
34 jython_utils.handle_error( error_log, str( e ) )