annotate jython_script.py @ 1:51188f1b546e draft

planemo upload commit 378c3ecfbaed0330faf197811d379431b0f9e92c-dirty
author iuc
date Sun, 11 Oct 2015 13:30:11 -0400
parents c43f184786a0
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
c43f184786a0 planemo upload commit 18df9e67efd4adafcde4eb9b62cd815e4afe9733-dirty
iuc
parents:
diff changeset
1 import jython_utils
c43f184786a0 planemo upload commit 18df9e67efd4adafcde4eb9b62cd815e4afe9733-dirty
iuc
parents:
diff changeset
2 import sys
c43f184786a0 planemo upload commit 18df9e67efd4adafcde4eb9b62cd815e4afe9733-dirty
iuc
parents:
diff changeset
3 from ij import IJ
c43f184786a0 planemo upload commit 18df9e67efd4adafcde4eb9b62cd815e4afe9733-dirty
iuc
parents:
diff changeset
4 from ij import ImagePlus
c43f184786a0 planemo upload commit 18df9e67efd4adafcde4eb9b62cd815e4afe9733-dirty
iuc
parents:
diff changeset
5 from ij.plugin.filter import Analyzer
c43f184786a0 planemo upload commit 18df9e67efd4adafcde4eb9b62cd815e4afe9733-dirty
iuc
parents:
diff changeset
6 from ij.plugin.filter import EDM
c43f184786a0 planemo upload commit 18df9e67efd4adafcde4eb9b62cd815e4afe9733-dirty
iuc
parents:
diff changeset
7
c43f184786a0 planemo upload commit 18df9e67efd4adafcde4eb9b62cd815e4afe9733-dirty
iuc
parents:
diff changeset
8 # Fiji Jython interpreter implements Python 2.5 which does not
c43f184786a0 planemo upload commit 18df9e67efd4adafcde4eb9b62cd815e4afe9733-dirty
iuc
parents:
diff changeset
9 # provide support for argparse.
c43f184786a0 planemo upload commit 18df9e67efd4adafcde4eb9b62cd815e4afe9733-dirty
iuc
parents:
diff changeset
10 error_log = sys.argv[ -8 ]
c43f184786a0 planemo upload commit 18df9e67efd4adafcde4eb9b62cd815e4afe9733-dirty
iuc
parents:
diff changeset
11 input = sys.argv[ -7 ]
c43f184786a0 planemo upload commit 18df9e67efd4adafcde4eb9b62cd815e4afe9733-dirty
iuc
parents:
diff changeset
12 iterations = int( sys.argv[ -6 ] )
c43f184786a0 planemo upload commit 18df9e67efd4adafcde4eb9b62cd815e4afe9733-dirty
iuc
parents:
diff changeset
13 count = int( sys.argv[ -5 ] )
c43f184786a0 planemo upload commit 18df9e67efd4adafcde4eb9b62cd815e4afe9733-dirty
iuc
parents:
diff changeset
14 black_background = jython_utils.asbool( sys.argv[ -4 ] )
c43f184786a0 planemo upload commit 18df9e67efd4adafcde4eb9b62cd815e4afe9733-dirty
iuc
parents:
diff changeset
15 pad_edges_when_eroding = jython_utils.asbool( sys.argv[ -3 ] )
c43f184786a0 planemo upload commit 18df9e67efd4adafcde4eb9b62cd815e4afe9733-dirty
iuc
parents:
diff changeset
16 tmp_output_path = sys.argv[ -2 ]
c43f184786a0 planemo upload commit 18df9e67efd4adafcde4eb9b62cd815e4afe9733-dirty
iuc
parents:
diff changeset
17 output_datatype = sys.argv[ -1 ]
c43f184786a0 planemo upload commit 18df9e67efd4adafcde4eb9b62cd815e4afe9733-dirty
iuc
parents:
diff changeset
18
c43f184786a0 planemo upload commit 18df9e67efd4adafcde4eb9b62cd815e4afe9733-dirty
iuc
parents:
diff changeset
19 # Open the input image file.
c43f184786a0 planemo upload commit 18df9e67efd4adafcde4eb9b62cd815e4afe9733-dirty
iuc
parents:
diff changeset
20 input_image_plus = IJ.openImage( input )
c43f184786a0 planemo upload commit 18df9e67efd4adafcde4eb9b62cd815e4afe9733-dirty
iuc
parents:
diff changeset
21
c43f184786a0 planemo upload commit 18df9e67efd4adafcde4eb9b62cd815e4afe9733-dirty
iuc
parents:
diff changeset
22 # Create a copy of the image.
c43f184786a0 planemo upload commit 18df9e67efd4adafcde4eb9b62cd815e4afe9733-dirty
iuc
parents:
diff changeset
23 input_image_plus_copy = input_image_plus.duplicate()
c43f184786a0 planemo upload commit 18df9e67efd4adafcde4eb9b62cd815e4afe9733-dirty
iuc
parents:
diff changeset
24 image_processor_copy = input_image_plus_copy.getProcessor()
c43f184786a0 planemo upload commit 18df9e67efd4adafcde4eb9b62cd815e4afe9733-dirty
iuc
parents:
diff changeset
25
c43f184786a0 planemo upload commit 18df9e67efd4adafcde4eb9b62cd815e4afe9733-dirty
iuc
parents:
diff changeset
26 try:
c43f184786a0 planemo upload commit 18df9e67efd4adafcde4eb9b62cd815e4afe9733-dirty
iuc
parents:
diff changeset
27 # Set binary options.
c43f184786a0 planemo upload commit 18df9e67efd4adafcde4eb9b62cd815e4afe9733-dirty
iuc
parents:
diff changeset
28 options = jython_utils.get_binary_options( black_background=black_background,
c43f184786a0 planemo upload commit 18df9e67efd4adafcde4eb9b62cd815e4afe9733-dirty
iuc
parents:
diff changeset
29 iterations=iterations,
c43f184786a0 planemo upload commit 18df9e67efd4adafcde4eb9b62cd815e4afe9733-dirty
iuc
parents:
diff changeset
30 count=count,
c43f184786a0 planemo upload commit 18df9e67efd4adafcde4eb9b62cd815e4afe9733-dirty
iuc
parents:
diff changeset
31 pad_edges_when_eroding=pad_edges_when_eroding )
c43f184786a0 planemo upload commit 18df9e67efd4adafcde4eb9b62cd815e4afe9733-dirty
iuc
parents:
diff changeset
32 IJ.run( input_image_plus_copy, "Options...", options )
c43f184786a0 planemo upload commit 18df9e67efd4adafcde4eb9b62cd815e4afe9733-dirty
iuc
parents:
diff changeset
33
c43f184786a0 planemo upload commit 18df9e67efd4adafcde4eb9b62cd815e4afe9733-dirty
iuc
parents:
diff changeset
34 # Convert image to binary if necessary.
c43f184786a0 planemo upload commit 18df9e67efd4adafcde4eb9b62cd815e4afe9733-dirty
iuc
parents:
diff changeset
35 if not image_processor_copy.isBinary():
c43f184786a0 planemo upload commit 18df9e67efd4adafcde4eb9b62cd815e4afe9733-dirty
iuc
parents:
diff changeset
36 # Convert the image to binary grayscale.
c43f184786a0 planemo upload commit 18df9e67efd4adafcde4eb9b62cd815e4afe9733-dirty
iuc
parents:
diff changeset
37 IJ.run( input_image_plus_copy, "Make Binary", "" )
c43f184786a0 planemo upload commit 18df9e67efd4adafcde4eb9b62cd815e4afe9733-dirty
iuc
parents:
diff changeset
38
c43f184786a0 planemo upload commit 18df9e67efd4adafcde4eb9b62cd815e4afe9733-dirty
iuc
parents:
diff changeset
39 # Run the command.
c43f184786a0 planemo upload commit 18df9e67efd4adafcde4eb9b62cd815e4afe9733-dirty
iuc
parents:
diff changeset
40 IJ.run( input_image_plus_copy, "Distance Map", "" )
c43f184786a0 planemo upload commit 18df9e67efd4adafcde4eb9b62cd815e4afe9733-dirty
iuc
parents:
diff changeset
41 # Save the ImagePlus object as a new image.
c43f184786a0 planemo upload commit 18df9e67efd4adafcde4eb9b62cd815e4afe9733-dirty
iuc
parents:
diff changeset
42 IJ.saveAs( input_image_plus_copy, output_datatype, tmp_output_path )
c43f184786a0 planemo upload commit 18df9e67efd4adafcde4eb9b62cd815e4afe9733-dirty
iuc
parents:
diff changeset
43 except Exception, e:
c43f184786a0 planemo upload commit 18df9e67efd4adafcde4eb9b62cd815e4afe9733-dirty
iuc
parents:
diff changeset
44 jython_utils.handle_error( error_log, str( e ) )