Mercurial > repos > imgteam > imagej2_crop
comparison imagej2_enhance_contrast_jython_script.py @ 0:db3066ae9b09 draft default tip
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
| author | imgteam |
|---|---|
| date | Wed, 25 Sep 2024 16:28:45 +0000 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:db3066ae9b09 |
|---|---|
| 1 import sys | |
| 2 | |
| 3 from ij import IJ | |
| 4 | |
| 5 # Fiji Jython interpreter implements Python 2.5 which does not | |
| 6 # provide support for argparse. | |
| 7 input = sys.argv[-6] | |
| 8 equalize_histogram = sys.argv[-5] == "yes" | |
| 9 saturated_pixels = sys.argv[-4] | |
| 10 normalize = sys.argv[-3] == "yes" | |
| 11 tmp_output_path = sys.argv[-2] | |
| 12 output_datatype = sys.argv[-1] | |
| 13 | |
| 14 # Open the input image file. | |
| 15 input_image_plus = IJ.openImage(input) | |
| 16 | |
| 17 # Create a copy of the image. | |
| 18 input_image_plus_copy = input_image_plus.duplicate() | |
| 19 image_processor_copy = input_image_plus_copy.getProcessor() | |
| 20 bit_depth = image_processor_copy.getBitDepth() | |
| 21 | |
| 22 # Set the options | |
| 23 options = [] | |
| 24 # If equalize_histogram, saturated_pixels and normalize are ignored. | |
| 25 if equalize_histogram: | |
| 26 options.append("equalize") | |
| 27 else: | |
| 28 if saturated_pixels not in [None, "None"]: | |
| 29 # Fiji allows only a single decimal place for this value. | |
| 30 options.append("saturated=%.3f" % float(saturated_pixels)) | |
| 31 # Normalization of RGB images is not supported. | |
| 32 if bit_depth != 24 and normalize: | |
| 33 options.append("normalize") | |
| 34 # Run the command. | |
| 35 options = "%s" % " ".join(options) | |
| 36 IJ.run(input_image_plus_copy, "Enhance Contrast...", options) | |
| 37 # Save the ImagePlus object as a new image. | |
| 38 IJ.saveAs(input_image_plus_copy, output_datatype, tmp_output_path) |
