Mercurial > repos > imgteam > imagej2_noise
comparison imagej2_noise_jython_script.py @ 1:7a44772cc89f 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:45:49 +0000 |
parents | 3f6599ec7d30 |
children | 756e062741dc |
comparison
equal
deleted
inserted
replaced
0:3f6599ec7d30 | 1:7a44772cc89f |
---|---|
1 import sys | 1 import sys |
2 | |
2 from ij import IJ | 3 from ij import IJ |
3 from ij import ImagePlus | |
4 import jython_utils | |
5 | 4 |
6 # Fiji Jython interpreter implements Python 2.5 which does not | 5 # Fiji Jython interpreter implements Python 2.5 which does not |
7 # provide support for argparse. | 6 # provide support for argparse. |
8 error_log = sys.argv[ -19 ] | 7 error_log = sys.argv[-19] |
9 input = sys.argv[ -18 ] | 8 input_file = sys.argv[-18] |
10 image_datatype = sys.argv[ -17 ] | 9 image_datatype = sys.argv[-17] |
11 noise = sys.argv[ -16 ] | 10 noise = sys.argv[-16] |
12 standard_deviation = sys.argv[ -15 ] | 11 standard_deviation = sys.argv[-15] |
13 radius = sys.argv[ -14 ] | 12 radius = sys.argv[-14] |
14 threshold = sys.argv[ -13 ] | 13 threshold = sys.argv[-13] |
15 which_outliers = sys.argv[ -12 ] | 14 which_outliers = sys.argv[-12] |
16 randomj = sys.argv[ -11 ] | 15 randomj = sys.argv[-11] |
17 trials = sys.argv[ -10 ] | 16 trials = sys.argv[-10] |
18 probability = sys.argv[ -9 ] | 17 probability = sys.argv[-9] |
19 # Note the spelling - so things don't get confused due to Python lambda function. | 18 # Note the spelling - so things don't get confused due to Python lambda function. |
20 lammbda = sys.argv[ -8 ] | 19 lammbda = sys.argv[-8] |
21 order = sys.argv[ -7 ] | 20 order = sys.argv[-7] |
22 mean = sys.argv[ -6 ] | 21 mean = sys.argv[-6] |
23 sigma = sys.argv[ -5 ] | 22 sigma = sys.argv[-5] |
24 min = sys.argv[ -4 ] | 23 min = sys.argv[-4] |
25 max = sys.argv[ -3 ] | 24 max = sys.argv[-3] |
26 insertion = sys.argv[ -2 ] | 25 insertion = sys.argv[-2] |
27 tmp_output_path = sys.argv[ -1 ] | 26 tmp_output_path = sys.argv[-1] |
28 | |
29 error = False | |
30 | 27 |
31 # Open the input image file. | 28 # Open the input image file. |
32 image_plus = IJ.openImage( input ) | 29 image_plus = IJ.openImage(input_file) |
33 bit_depth = image_plus.getBitDepth() | 30 bit_depth = image_plus.getBitDepth() |
34 image_type = image_plus.getType() | 31 image_type = image_plus.getType() |
35 # Create an ImagePlus object for the image. | 32 # Create an ImagePlus object for the image. |
36 image_plus_copy = image_plus.duplicate() | 33 image_plus_copy = image_plus.duplicate() |
37 # Make a copy of the image. | 34 # Make a copy of the image. |
38 image_processor_copy = image_plus_copy.getProcessor() | 35 image_processor_copy = image_plus_copy.getProcessor() |
39 | 36 |
40 # Perform the analysis on the ImagePlus object. | 37 # Perform the analysis on the ImagePlus object. |
41 if noise == 'add_noise': | 38 if noise == 'add_noise': |
42 IJ.run( image_plus_copy, "Add Noise", "" ) | 39 IJ.run(image_plus_copy, "Add Noise", "") |
43 elif noise == 'add_specified_noise': | 40 elif noise == 'add_specified_noise': |
44 IJ.run( image_plus_copy, "Add Specified Noise", "standard=&standard_deviation" ) | 41 IJ.run(image_plus_copy, "Add Specified Noise", "standard=&standard_deviation") |
45 elif noise == 'salt_and_pepper': | 42 elif noise == 'salt_and_pepper': |
46 IJ.run( image_plus_copy, "Salt and Pepper", "" ) | 43 IJ.run(image_plus_copy, "Salt and Pepper", "") |
47 elif noise == 'despeckle': | 44 elif noise == 'despeckle': |
48 IJ.run( image_plus_copy, "Despeckle", "" ) | 45 IJ.run(image_plus_copy, "Despeckle", "") |
49 elif noise == 'remove_outliers': | 46 elif noise == 'remove_outliers': |
50 IJ.run( image_plus_copy, "Remove Outliers", "radius=&radius threshold=&threshold which=&which_outliers" ) | 47 IJ.run(image_plus_copy, "Remove Outliers", "radius=&radius threshold=&threshold which=&which_outliers") |
51 elif noise == 'remove_nans': | 48 elif noise == 'remove_nans': |
52 if bit_depth == 32: | 49 IJ.run(image_plus_copy, "Remove NaNs", "") |
53 IJ.run( image_plus_copy, "Remove NaNs", "" ) | |
54 else: | |
55 # When Galaxy metadata for images is enhanced to include information like this, | |
56 # we'll be able to write tool validators rather than having to stop the job in | |
57 # an error state. | |
58 msg = "Remove NaNs requires a 32-bit image, the selected image is %d-bit" % bit_depth | |
59 jython_utils.handle_error( error_log, msg ) | |
60 error = True | |
61 elif noise == 'rof_denoise': | 50 elif noise == 'rof_denoise': |
62 if image_type == ImagePlus.GRAY32: | 51 IJ.run(image_plus_copy, "ROF Denoise", "") |
63 IJ.run( image_plus_copy, "ROF Denoise", "" ) | |
64 else: | |
65 msg = "ROF Denoise requires an image of type 32-bit grayscale, the selected image is %d-bit" % ( bit_depth ) | |
66 jython_utils.handle_error( error_log, msg ) | |
67 error = True | |
68 elif noise == 'randomj': | 52 elif noise == 'randomj': |
69 if randomj == 'randomj_binomial': | 53 if randomj == 'randomj_binomial': |
70 IJ.run( image_plus_copy, "RandomJ Binomial", "trials=&trials probability=&probability insertion=&insertion" ) | 54 IJ.run(image_plus_copy, "RandomJ Binomial", "trials=&trials probability=&probability insertion=&insertion") |
71 elif randomj == 'randomj_exponential': | 55 elif randomj == 'randomj_exponential': |
72 IJ.run( image_plus_copy, "RandomJ Exponential", "lambda=&lammbda insertion=&insertion" ) | 56 IJ.run(image_plus_copy, "RandomJ Exponential", "lambda=&lammbda insertion=&insertion") |
73 elif randomj == 'randomj_gamma': | 57 elif randomj == 'randomj_gamma': |
74 IJ.run( image_plus_copy, "RandomJ Gamma", "order=&order insertion=&insertion" ) | 58 IJ.run(image_plus_copy, "RandomJ Gamma", "order=&order insertion=&insertion") |
75 elif randomj == 'randomj_gaussian': | 59 elif randomj == 'randomj_gaussian': |
76 IJ.run( image_plus_copy, "RandomJ Gaussian", "mean=&mean sigma=&sigma insertion=&insertion" ) | 60 IJ.run(image_plus_copy, "RandomJ Gaussian", "mean=&mean sigma=&sigma insertion=&insertion") |
77 elif randomj == 'randomj_poisson': | 61 elif randomj == 'randomj_poisson': |
78 IJ.run( image_plus_copy, "RandomJ Poisson", "mean=&mean insertion=&insertion" ) | 62 IJ.run(image_plus_copy, "RandomJ Poisson", "mean=&mean insertion=&insertion") |
79 elif randomj == 'randomj_uniform': | 63 elif randomj == 'randomj_uniform': |
80 IJ.run( image_plus_copy, "RandomJ Uniform", "min=&min max=&max insertion=&insertion" ) | 64 IJ.run(image_plus_copy, "RandomJ Uniform", "min=&min max=&max insertion=&insertion") |
81 | 65 |
82 if not error: | 66 # Save the ImagePlus object as a new image. |
83 # Save the ImagePlus object as a new image. | 67 IJ.saveAs(image_plus_copy, image_datatype, tmp_output_path) |
84 IJ.saveAs( image_plus_copy, image_datatype, tmp_output_path ) |