Mercurial > repos > imgteam > imagej2_analyze_skeleton
diff imagej2_noise_jython_script.py @ 1:3272e0439968 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:52:29 +0000 |
parents | bb84f130a4e1 |
children | bdee06a1bcfa |
line wrap: on
line diff
--- a/imagej2_noise_jython_script.py Tue Sep 17 17:04:59 2019 -0400 +++ b/imagej2_noise_jython_script.py Mon Sep 28 16:52:29 2020 +0000 @@ -1,35 +1,32 @@ import sys + from ij import IJ -from ij import ImagePlus -import jython_utils # Fiji Jython interpreter implements Python 2.5 which does not # provide support for argparse. -error_log = sys.argv[ -19 ] -input = sys.argv[ -18 ] -image_datatype = sys.argv[ -17 ] -noise = sys.argv[ -16 ] -standard_deviation = sys.argv[ -15 ] -radius = sys.argv[ -14 ] -threshold = sys.argv[ -13 ] -which_outliers = sys.argv[ -12 ] -randomj = sys.argv[ -11 ] -trials = sys.argv[ -10 ] -probability = sys.argv[ -9 ] +error_log = sys.argv[-19] +input_file = sys.argv[-18] +image_datatype = sys.argv[-17] +noise = sys.argv[-16] +standard_deviation = sys.argv[-15] +radius = sys.argv[-14] +threshold = sys.argv[-13] +which_outliers = sys.argv[-12] +randomj = sys.argv[-11] +trials = sys.argv[-10] +probability = sys.argv[-9] # Note the spelling - so things don't get confused due to Python lambda function. -lammbda = sys.argv[ -8 ] -order = sys.argv[ -7 ] -mean = sys.argv[ -6 ] -sigma = sys.argv[ -5 ] -min = sys.argv[ -4 ] -max = sys.argv[ -3 ] -insertion = sys.argv[ -2 ] -tmp_output_path = sys.argv[ -1 ] - -error = False +lammbda = sys.argv[-8] +order = sys.argv[-7] +mean = sys.argv[-6] +sigma = sys.argv[-5] +min = sys.argv[-4] +max = sys.argv[-3] +insertion = sys.argv[-2] +tmp_output_path = sys.argv[-1] # Open the input image file. -image_plus = IJ.openImage( input ) +image_plus = IJ.openImage(input_file) bit_depth = image_plus.getBitDepth() image_type = image_plus.getType() # Create an ImagePlus object for the image. @@ -39,46 +36,32 @@ # Perform the analysis on the ImagePlus object. if noise == 'add_noise': - IJ.run( image_plus_copy, "Add Noise", "" ) + IJ.run(image_plus_copy, "Add Noise", "") elif noise == 'add_specified_noise': - IJ.run( image_plus_copy, "Add Specified Noise", "standard=&standard_deviation" ) + IJ.run(image_plus_copy, "Add Specified Noise", "standard=&standard_deviation") elif noise == 'salt_and_pepper': - IJ.run( image_plus_copy, "Salt and Pepper", "" ) + IJ.run(image_plus_copy, "Salt and Pepper", "") elif noise == 'despeckle': - IJ.run( image_plus_copy, "Despeckle", "" ) + IJ.run(image_plus_copy, "Despeckle", "") elif noise == 'remove_outliers': - IJ.run( image_plus_copy, "Remove Outliers", "radius=&radius threshold=&threshold which=&which_outliers" ) + IJ.run(image_plus_copy, "Remove Outliers", "radius=&radius threshold=&threshold which=&which_outliers") elif noise == 'remove_nans': - if bit_depth == 32: - IJ.run( image_plus_copy, "Remove NaNs", "" ) - else: - # When Galaxy metadata for images is enhanced to include information like this, - # we'll be able to write tool validators rather than having to stop the job in - # an error state. - msg = "Remove NaNs requires a 32-bit image, the selected image is %d-bit" % bit_depth - jython_utils.handle_error( error_log, msg ) - error = True + IJ.run(image_plus_copy, "Remove NaNs", "") elif noise == 'rof_denoise': - if image_type == ImagePlus.GRAY32: - IJ.run( image_plus_copy, "ROF Denoise", "" ) - else: - msg = "ROF Denoise requires an image of type 32-bit grayscale, the selected image is %d-bit" % ( bit_depth ) - jython_utils.handle_error( error_log, msg ) - error = True + IJ.run(image_plus_copy, "ROF Denoise", "") elif noise == 'randomj': if randomj == 'randomj_binomial': - IJ.run( image_plus_copy, "RandomJ Binomial", "trials=&trials probability=&probability insertion=&insertion" ) + IJ.run(image_plus_copy, "RandomJ Binomial", "trials=&trials probability=&probability insertion=&insertion") elif randomj == 'randomj_exponential': - IJ.run( image_plus_copy, "RandomJ Exponential", "lambda=&lammbda insertion=&insertion" ) + IJ.run(image_plus_copy, "RandomJ Exponential", "lambda=&lammbda insertion=&insertion") elif randomj == 'randomj_gamma': - IJ.run( image_plus_copy, "RandomJ Gamma", "order=&order insertion=&insertion" ) + IJ.run(image_plus_copy, "RandomJ Gamma", "order=&order insertion=&insertion") elif randomj == 'randomj_gaussian': - IJ.run( image_plus_copy, "RandomJ Gaussian", "mean=&mean sigma=&sigma insertion=&insertion" ) + IJ.run(image_plus_copy, "RandomJ Gaussian", "mean=&mean sigma=&sigma insertion=&insertion") elif randomj == 'randomj_poisson': - IJ.run( image_plus_copy, "RandomJ Poisson", "mean=&mean insertion=&insertion" ) + IJ.run(image_plus_copy, "RandomJ Poisson", "mean=&mean insertion=&insertion") elif randomj == 'randomj_uniform': - IJ.run( image_plus_copy, "RandomJ Uniform", "min=&min max=&max insertion=&insertion" ) + IJ.run(image_plus_copy, "RandomJ Uniform", "min=&min max=&max insertion=&insertion") -if not error: - # Save the ImagePlus object as a new image. - IJ.saveAs( image_plus_copy, image_datatype, tmp_output_path ) +# Save the ImagePlus object as a new image. +IJ.saveAs(image_plus_copy, image_datatype, tmp_output_path)