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