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