annotate jython_script.py @ 0:66d9e595dff2 draft

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