Mercurial > repos > imgteam > imagej2_bunwarpj_compose_elastic
comparison imagej2_enhance_contrast_jython_script.py @ 1:423400b3c47f 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:47:44 +0000 |
parents | 6840ce593a91 |
children | 7121957d0bbf |
comparison
equal
deleted
inserted
replaced
0:6840ce593a91 | 1:423400b3c47f |
---|---|
1 import jython_utils | |
2 import sys | 1 import sys |
2 | |
3 from ij import IJ | 3 from ij import IJ |
4 | 4 |
5 # Fiji Jython interpreter implements Python 2.5 which does not | 5 # Fiji Jython interpreter implements Python 2.5 which does not |
6 # provide support for argparse. | 6 # provide support for argparse. |
7 error_log = sys.argv[ -7 ] | 7 error_log = sys.argv[-7] |
8 input = sys.argv[ -6 ] | 8 input = sys.argv[-6] |
9 equalize_histogram = jython_utils.asbool( sys.argv[ -5 ] ) | 9 equalize_histogram = sys.argv[-5] == "yes" |
10 saturated_pixels = sys.argv[ -4 ] | 10 saturated_pixels = sys.argv[-4] |
11 normalize = jython_utils.asbool( sys.argv[ -3 ] ) | 11 normalize = sys.argv[-3] == "yes" |
12 tmp_output_path = sys.argv[ -2 ] | 12 tmp_output_path = sys.argv[-2] |
13 output_datatype = sys.argv[ -1 ] | 13 output_datatype = sys.argv[-1] |
14 | 14 |
15 # Open the input image file. | 15 # Open the input image file. |
16 input_image_plus = IJ.openImage( input ) | 16 input_image_plus = IJ.openImage(input) |
17 | 17 |
18 # Create a copy of the image. | 18 # Create a copy of the image. |
19 input_image_plus_copy = input_image_plus.duplicate() | 19 input_image_plus_copy = input_image_plus.duplicate() |
20 image_processor_copy = input_image_plus_copy.getProcessor() | 20 image_processor_copy = input_image_plus_copy.getProcessor() |
21 bit_depth = image_processor_copy.getBitDepth() | 21 bit_depth = image_processor_copy.getBitDepth() |
22 | 22 |
23 # Set the options | 23 # Set the options |
24 options = [] | 24 options = [] |
25 # If equalize_histogram, saturated_pixels and normalize are ignored. | 25 # If equalize_histogram, saturated_pixels and normalize are ignored. |
26 if equalize_histogram: | 26 if equalize_histogram: |
27 options.append( 'equalize' ) | 27 options.append('equalize') |
28 else: | 28 else: |
29 if saturated_pixels not in [ None, 'None' ]: | 29 if saturated_pixels not in [None, 'None']: |
30 # Fiji allows only a single decimal place for this value. | 30 # Fiji allows only a single decimal place for this value. |
31 options.append( 'saturated=%.3f' % float( saturated_pixels ) ) | 31 options.append('saturated=%.3f' % float(saturated_pixels)) |
32 # Normalization of RGB images is not supported. | 32 # Normalization of RGB images is not supported. |
33 if bit_depth != 24 and normalize: | 33 if bit_depth != 24 and normalize: |
34 options.append( 'normalize' ) | 34 options.append('normalize') |
35 try: | 35 # Run the command. |
36 # Run the command. | 36 options = "%s" % ' '.join(options) |
37 options = "%s" % ' '.join( options ) | 37 IJ.run(input_image_plus_copy, "Enhance Contrast...", options) |
38 IJ.run( input_image_plus_copy, "Enhance Contrast...", options ) | 38 # Save the ImagePlus object as a new image. |
39 # Save the ImagePlus object as a new image. | 39 IJ.saveAs(input_image_plus_copy, output_datatype, tmp_output_path) |
40 IJ.saveAs( input_image_plus_copy, output_datatype, tmp_output_path ) | |
41 except Exception, e: | |
42 jython_utils.handle_error( error_log, str( e ) ) |