comparison imagej2_analyze_particles_binary_jython_script.py @ 0:7baf811ed973 draft

"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
author imgteam
date Tue, 17 Sep 2019 16:59:39 -0400
parents
children c8bb47840c8d
comparison
equal deleted inserted replaced
-1:000000000000 0:7baf811ed973
1 import jython_utils
2 import sys
3 from ij import IJ
4 from ij.plugin.filter import Analyzer
5
6 # Fiji Jython interpreter implements Python 2.5 which does not
7 # provide support for argparse.
8 error_log = sys.argv[ -14 ]
9 input = sys.argv[ -13 ]
10 black_background = jython_utils.asbool( sys.argv[ -12 ] )
11 size = sys.argv[ -11 ]
12 circularity_min = float( sys.argv[ -10 ] )
13 circularity_max = float( sys.argv[ -9 ] )
14 show = sys.argv[ -8 ]
15 display_results = jython_utils.asbool( sys.argv[ -7 ] )
16 all_results = jython_utils.asbool( sys.argv[ -6 ] )
17 exclude_edges = jython_utils.asbool( sys.argv[ -5 ] )
18 include_holes = jython_utils.asbool( sys.argv[ -4 ] )
19 tmp_output_path = sys.argv[ -3 ]
20 output_datatype = sys.argv[ -2 ]
21 results_path = sys.argv[ -1 ]
22
23 # Open the input image file.
24 input_image_plus = IJ.openImage( input )
25
26 # Create a copy of the image.
27 input_image_plus_copy = input_image_plus.duplicate()
28 image_processor_copy = input_image_plus_copy.getProcessor()
29 analyzer = Analyzer( input_image_plus_copy )
30
31 try:
32 # Set binary options.
33 options = jython_utils.get_binary_options( black_background=black_background )
34 IJ.run( input_image_plus_copy, "Options...", options )
35
36 # Convert image to binary if necessary.
37 if not image_processor_copy.isBinary():
38 # Convert the image to binary grayscale.
39 IJ.run( input_image_plus_copy, "Make Binary", "" )
40
41 # Set the options.
42 options = [ 'size=%s' % size ]
43 circularity_str = '%.3f-%.3f' % ( circularity_min, circularity_max )
44 options.append( 'circularity=%s' % circularity_str )
45 if show.find( '_' ) >= 0:
46 show_str = '[%s]' % show.replace( '_', ' ' )
47 else:
48 show_str = show
49 options.append( 'show=%s' % show_str )
50 if display_results:
51 options.append( 'display' )
52 if not all_results:
53 options.append( 'summarize' )
54 if exclude_edges:
55 options.append( 'exclude' )
56 if include_holes:
57 options.append( 'include' )
58 # Always run "in_situ".
59 options.append( 'in_situ' )
60
61 # Run the command.
62 IJ.run( input_image_plus_copy, "Analyze Particles...", " ".join( options ) )
63
64 # Save outputs.
65 if tmp_output_path not in [ None, 'None' ]:
66 # Save the ImagePlus object as a new image.
67 IJ.saveAs( input_image_plus_copy, output_datatype, tmp_output_path )
68 if display_results and results_path not in [ None, 'None' ]:
69 results_table = analyzer.getResultsTable()
70 results_table.saveAs( results_path )
71 except Exception, e:
72 jython_utils.handle_error( error_log, str( e ) )