Mercurial > repos > imgteam > imagej2_find_edges
comparison imagej2_noise_jython_script.py @ 0:8e608a6e44ac 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 16:59:03 -0400 |
parents | |
children | c8dfbf4b899c |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:8e608a6e44ac |
---|---|
1 import sys | |
2 from ij import IJ | |
3 from ij import ImagePlus | |
4 import jython_utils | |
5 | |
6 # Fiji Jython interpreter implements Python 2.5 which does not | |
7 # provide support for argparse. | |
8 error_log = sys.argv[ -19 ] | |
9 input = sys.argv[ -18 ] | |
10 image_datatype = sys.argv[ -17 ] | |
11 noise = sys.argv[ -16 ] | |
12 standard_deviation = sys.argv[ -15 ] | |
13 radius = sys.argv[ -14 ] | |
14 threshold = sys.argv[ -13 ] | |
15 which_outliers = sys.argv[ -12 ] | |
16 randomj = sys.argv[ -11 ] | |
17 trials = sys.argv[ -10 ] | |
18 probability = sys.argv[ -9 ] | |
19 # Note the spelling - so things don't get confused due to Python lambda function. | |
20 lammbda = sys.argv[ -8 ] | |
21 order = sys.argv[ -7 ] | |
22 mean = sys.argv[ -6 ] | |
23 sigma = sys.argv[ -5 ] | |
24 min = sys.argv[ -4 ] | |
25 max = sys.argv[ -3 ] | |
26 insertion = sys.argv[ -2 ] | |
27 tmp_output_path = sys.argv[ -1 ] | |
28 | |
29 error = False | |
30 | |
31 # Open the input image file. | |
32 image_plus = IJ.openImage( input ) | |
33 bit_depth = image_plus.getBitDepth() | |
34 image_type = image_plus.getType() | |
35 # Create an ImagePlus object for the image. | |
36 image_plus_copy = image_plus.duplicate() | |
37 # Make a copy of the image. | |
38 image_processor_copy = image_plus_copy.getProcessor() | |
39 | |
40 # Perform the analysis on the ImagePlus object. | |
41 if noise == 'add_noise': | |
42 IJ.run( image_plus_copy, "Add Noise", "" ) | |
43 elif noise == 'add_specified_noise': | |
44 IJ.run( image_plus_copy, "Add Specified Noise", "standard=&standard_deviation" ) | |
45 elif noise == 'salt_and_pepper': | |
46 IJ.run( image_plus_copy, "Salt and Pepper", "" ) | |
47 elif noise == 'despeckle': | |
48 IJ.run( image_plus_copy, "Despeckle", "" ) | |
49 elif noise == 'remove_outliers': | |
50 IJ.run( image_plus_copy, "Remove Outliers", "radius=&radius threshold=&threshold which=&which_outliers" ) | |
51 elif noise == 'remove_nans': | |
52 if bit_depth == 32: | |
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': | |
62 if image_type == ImagePlus.GRAY32: | |
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': | |
69 if randomj == 'randomj_binomial': | |
70 IJ.run( image_plus_copy, "RandomJ Binomial", "trials=&trials probability=&probability insertion=&insertion" ) | |
71 elif randomj == 'randomj_exponential': | |
72 IJ.run( image_plus_copy, "RandomJ Exponential", "lambda=&lammbda insertion=&insertion" ) | |
73 elif randomj == 'randomj_gamma': | |
74 IJ.run( image_plus_copy, "RandomJ Gamma", "order=&order insertion=&insertion" ) | |
75 elif randomj == 'randomj_gaussian': | |
76 IJ.run( image_plus_copy, "RandomJ Gaussian", "mean=&mean sigma=&sigma insertion=&insertion" ) | |
77 elif randomj == 'randomj_poisson': | |
78 IJ.run( image_plus_copy, "RandomJ Poisson", "mean=&mean insertion=&insertion" ) | |
79 elif randomj == 'randomj_uniform': | |
80 IJ.run( image_plus_copy, "RandomJ Uniform", "min=&min max=&max insertion=&insertion" ) | |
81 | |
82 if not error: | |
83 # Save the ImagePlus object as a new image. | |
84 IJ.saveAs( image_plus_copy, image_datatype, tmp_output_path ) |