Mercurial > repos > iuc > imagej2_noise
changeset 0:da9a450c85b7 draft
planemo upload commit 7195716d447effc5bc32154279de4b84369eccdb-dirty
| author | iuc |
|---|---|
| date | Fri, 19 Jun 2015 16:59:22 -0400 |
| parents | |
| children | 1af4f60294c3 |
| files | imagej2_base_utils.py imagej2_macros.xml imagej2_noise.py imagej2_noise.xml jython_script.py test-data/add_specified_noise.gif test-data/blobs.gif test-data/despeckle.gif test-data/remove_outliers.gif tool_dependencies.xml |
| diffstat | 10 files changed, 599 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/imagej2_base_utils.py Fri Jun 19 16:59:22 2015 -0400 @@ -0,0 +1,156 @@ +import os +import shutil +import sys +import tempfile + +FIJI_JAR_DIR = os.environ.get( 'FIJI_JAR_DIR', None ) +FIJI_OSX_JAVA3D_DIR = os.environ.get( 'FIJI_OSX_JAVA3D_DIR', None ) +FIJI_PLUGIN_DIR = os.environ.get( 'FIJI_PLUGIN_DIR', None ) +FIJI_ROOT_DIR = os.environ.get( 'FIJI_ROOT_DIR', None ) + +BUFF_SIZE = 1048576 + +def cleanup_before_exit( tmp_dir ): + """ + Remove temporary files and directories prior to tool exit. + """ + if tmp_dir and os.path.exists( tmp_dir ): + shutil.rmtree( tmp_dir ) + +def get_base_cmd_bunwarpj( jvm_memory ): + if FIJI_JAR_DIR is not None and FIJI_PLUGIN_DIR is not None: + if jvm_memory in [ None, 'None' ]: + jvm_memory_str = '' + else: + jvm_memory_str = '-Xmx%s' % jvm_memory + bunwarpj_base_cmd = "java %s -cp %s/ij-1.49k.jar:%s/bUnwarpJ_-2.6.1.jar bunwarpj.bUnwarpJ_" % \ + ( jvm_memory_str, FIJI_JAR_DIR, FIJI_PLUGIN_DIR ) + return bunwarpj_base_cmd + return None + +def get_base_command_imagej2( memory_size=None, macro=None, jython_script=None ): + imagej2_executable = get_imagej2_executable() + if imagej2_executable: + cmd = '%s --headless -DXincgc' % imagej2_executable + if memory_size is not None: + memory_size_cmd = ' -DXms=%s -DXmx=%s' % ( memory_size, memory_size ) + cmd += memory_size_cmd + if macro is not None: + cmd += ' --macro %s' % os.path.abspath( macro ) + if jython_script is not None: + cmd += ' --jython -u %s' % os.path.abspath( jython_script ) + return cmd + return None + +def get_file_extension( image_format ): + """ + Return a valid bioformats file extension based on the received + value of image_format( e.g., "gif" is returned as ".gif". + """ + return '.%s' % image_format + +def get_file_name_without_extension( file_path ): + """ + Eliminate the .ext from the received file name, assuming that + the file name consists of only a single '.'. + """ + if os.path.exists( file_path ): + path, name = os.path.split( file_path ) + name_items = name.split( '.' ) + return name_items[ 0 ] + return None + +def get_imagej2_executable(): + """ + Fiji names the ImageJ executable different names for different + architectures, so figure out which name we need. + """ + platform_dict = get_platform_info_dict() + if platform_dict.get( 'architecture', None ) in [ 'x86_64' ]: + if platform_dict.get( 'os', None ) in [ 'darwin' ]: + return 'ImageJ-macosx' + if platform_dict.get( 'os', None ) in [ 'linux' ]: + return 'ImageJ-linux64' + return None + +def get_input_image_path( tmp_dir, input_file, image_format ): + """ + Bioformats uses file extensions (e.g., .job, .gif, etc) + when reading and writing image files, so the Galaxy dataset + naming convention of setting all file extensions as .dat + must be handled. + """ + image_path = get_temporary_image_path( tmp_dir, image_format ) + # Remove the file so we can create a symlink. + os.remove( image_path ) + os.symlink( input_file, image_path ) + return image_path + +def get_max_heap_size_value( max_heap_size_type, max_heap_size ): + """ + Return a string that can be used by the javabridge to set the size + of the memory allocation pool used by the JVM. The value must be + determined to be a multiple of 1024 or it will be ignored. + """ + if max_heap_size_type == 'default': + return None + if max_heap_size_type == 'megabytes': + if max_heap_size % 1024 not in [ 0, 256, 512 ]: + return None + return '%sm' % str( max_heap_size ) + if max_heap_size_type == 'gigabytes': + return '%sg' % str( max_heap_size ) + +def get_platform_info_dict(): + '''Return a dict with information about the current platform.''' + platform_dict = {} + sysname, nodename, release, version, machine = os.uname() + platform_dict[ 'os' ] = sysname.lower() + platform_dict[ 'architecture' ] = machine.lower() + return platform_dict + +def get_stderr_exception( tmp_err, tmp_stderr, tmp_stdout ): + tmp_stderr.close() + """ + Return a stderr string of reasonable size. + """ + # Get stderr, allowing for case where it's very large. + tmp_stderr = open( tmp_err, 'rb' ) + stderr_str = '' + buffsize = BUFF_SIZE + try: + while True: + stderr_str += tmp_stderr.read( buffsize ) + if not stderr_str or len( stderr_str ) % buffsize != 0: + break + except OverflowError: + pass + tmp_stderr.close() + tmp_stdout.close() + return str( stderr_str ) + +def get_temp_dir( prefix='tmp-imagej-', dir=None ): + """ + Return a temporary directory. + """ + return tempfile.mkdtemp( prefix=prefix, dir=dir ) + +def get_tempfilename( dir=None, suffix=None ): + """ + Return a temporary file name. + """ + fd, name = tempfile.mkstemp( suffix=suffix, dir=dir ) + os.close( fd ) + return name + +def get_temporary_image_path( tmp_dir, image_format ): + """ + Return the path to a temporary file with a valid image format + file extension that can be used with bioformats. + """ + file_extension = get_file_extension( image_format ) + return get_tempfilename( tmp_dir, file_extension ) + +def stop_err( msg ): + sys.stderr.write( msg ) + sys.exit( 1 )
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/imagej2_macros.xml Fri Jun 19 16:59:22 2015 -0400 @@ -0,0 +1,81 @@ +<?xml version='1.0' encoding='UTF-8'?> +<macros> + <xml name="fiji_headless_requirements"> + <requirements> + <requirement type="package" version="20141125">fiji</requirement> + </requirements> + </xml> + <xml name="python_bioformats_requirements"> + <requirements> + <requirement type="package" version="20141125">fiji</requirement> + <requirement type="package" version="1.0.11">javabridge</requirement> + <requirement type="package" version="1.9">numpy</requirement> + <requirement type="package" version="1.0.4">python_bioformats</requirement> + </requirements> + </xml> + <xml name="stdio"> + <stdio> + <exit_code range="1:"/> + <exit_code range=":-1"/> + <regex match="Error:"/> + <regex match="Exception:"/> + </stdio> + </xml> + <xml name="image_type"> + <param name="image_type" type="select" label="Image type"> + <option value="8-bit_white" selected="True">8-bit white</option> + <option value="8-bit_black">8-bit black</option> + <option value="8-bit_random">8-bit random</option> + <option value="8-bit_ramp">8-bit ramp</option> + <option value="16-bit_white">16-bit white</option> + <option value="16-bit_black">16-bit black</option> + <option value="16-bit_random">16-bit random</option> + <option value="16-bit_ramp">16-bit ramp</option> + <option value="32-bit_white">32-bit white</option> + <option value="32-bit_black">32-bit black</option> + <option value="32-bit_random">32-bit random</option> + <option value="32-bit_ramp">32-bit ramp</option> + <option value="RGB_white">RGB white</option> + <option value="RGB_black">RGB black</option> + <option value="RGB_random">RGB random</option> + <option value="RGB_ramp">RGB ramp</option> + </param> + </xml> + <xml name="max_heap_size_type_conditional"> + <conditional name="set_max_heap_size"> + <param name="max_heap_size_type" type="select" label="Maximum size of the memory allocation pool used by the JVM" help="This value must be a multiple of 1024 or it will be ignored and the system default will be used."> + <option value="default" selected="True">Do not set</option> + <option value="megabytes">Set in megabytes</option> + <option value="gigabytes">Set in gigabytes</option> + </param> + <when value="default"> + <param name="max_heap_size" type="integer" value="0" label="Do not set" help="Use system default"/> + </when> + <when value="megabytes"> + <param name="max_heap_size" type="integer" value="512" min="256" label="Maximum size, in megabytes, of the memory allocation pool" help="Examples: 256, 512, etc."/> + </when> + <when value="gigabytes"> + <param name="max_heap_size" type="integer" value="1" min="1" label="Maximum size, in gigabytes, of the memory allocation pool" help="Examples: 1, 2, etc."/> + </when> + </conditional> + </xml> + <xml name="image_datatypes"> + <option value="bmp">bmp</option> + <option value="gif">gif</option> + <option value="jpg">jpg</option> + <option value="png" selected="true">png</option> + <option value="tiff">tiff</option> + </xml> + <xml name="fiji_headless_citations"> + <citations> + <citation type="doi">10.1038/nmeth.2102</citation> + </citations> + </xml> + <xml name="citations"> + <citations> + <citation type="doi">10.1038/nmeth.2102</citation> + <citation type="doi">10.1038/nmeth.2019</citation> + <citation type="doi">10.1083/jcb.201004104</citation> + </citations> + </xml> +</macros>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/imagej2_noise.py Fri Jun 19 16:59:22 2015 -0400 @@ -0,0 +1,97 @@ +#!/usr/bin/env python +import argparse +import os +import shutil +import subprocess +import tempfile +import imagej2_base_utils + +def handle_none_type( val, val_type='float' ): + if val is None: + return ' None' + else: + if val_type == 'float': + return ' %.1f' % val + elif val_type == 'int': + return ' %d' % val + +if __name__=="__main__": + # Parse Command Line. + parser = argparse.ArgumentParser() + parser.add_argument( '--input', dest='input', help='Path to the input file' ) + parser.add_argument( '--input_datatype', dest='input_datatype', help='Datatype of the input image' ) + parser.add_argument( '--noise', dest='noise', help='Specified noise to add to or remove from the image' ) + parser.add_argument( '--standard_deviation', dest='standard_deviation', type=float, default=None, help='Standard deviation' ) + parser.add_argument( '--radius', dest='radius', type=float, default=None, help='Radius' ) + parser.add_argument( '--threshold', dest='threshold', type=float, default=None, help='Threshold' ) + parser.add_argument( '--which_outliers', dest='which_outliers', default=None, help='Which outliers' ) + parser.add_argument( '--randomj', dest='randomj', default=None, help='RandomJ' ) + parser.add_argument( '--trials', dest='trials', type=float, default=None, help='Trials' ) + parser.add_argument( '--probability', dest='probability', type=float, default=None, help='Probability' ) + parser.add_argument( '--lammbda', dest='lammbda', type=float, default=None, help='Lambda' ) + parser.add_argument( '--order', dest='order', type=int, default=None, help='Order' ) + parser.add_argument( '--mean', dest='mean', type=float, default=None, help='Mean' ) + parser.add_argument( '--sigma', dest='sigma', type=float, default=None, help='Sigma' ) + parser.add_argument( '--min', dest='min', type=float, default=None, help='Min' ) + parser.add_argument( '--max', dest='max', type=float, default=None, help='Max' ) + parser.add_argument( '--insertion', dest='insertion', default=None, help='Insertion' ) + parser.add_argument( '--jython_script', dest='jython_script', help='Path to the Jython script' ) + parser.add_argument( '--max_heap_size_type', dest='max_heap_size_type', help='Type (default or megabytes) of max_heap_size value' ) + parser.add_argument( '--max_heap_size', dest='max_heap_size', help='Maximum size of the memory allocation pool used by the JVM.' ) + parser.add_argument( '--output', help='Path to the output file' ) + args = parser.parse_args() + + tmp_dir = imagej2_base_utils.get_temp_dir() + # ImageJ expects valid image file extensions, so the Galaxy .dat extension does not + # work for some features. The following creates a symlink with an appropriate file + # extension that points to the Galaxy dataset. This symlink is used by ImageJ. + tmp_input_path = imagej2_base_utils.get_input_image_path( tmp_dir, args.input, args.input_datatype ) + tmp_output_path = imagej2_base_utils.get_temporary_image_path( tmp_dir, args.input_datatype ) + # Set the size of the memory allocation pool used by the JVM. + memory_size = imagej2_base_utils.get_max_heap_size_value( args.max_heap_size_type, args.max_heap_size ) + + # Define command response buffers. + tmp_out = tempfile.NamedTemporaryFile().name + tmp_stdout = open( tmp_out, 'wb' ) + tmp_err = tempfile.NamedTemporaryFile().name + tmp_stderr = open( tmp_err, 'wb' ) + # Java writes a lot of stuff to stderr, so we'll specify a file for handling actual errors. + error_log = tempfile.NamedTemporaryFile( delete=False ).name + # Build the command line. + cmd = imagej2_base_utils.get_base_command_imagej2( memory_size, jython_script=args.jython_script ) + if cmd is None: + imagej2_base_utils.stop_err( "ImageJ not found!" ) + cmd += ' %s' % error_log + cmd += ' %s' % tmp_input_path + cmd += ' %s' % args.input_datatype + cmd += ' %s ' % args.noise + cmd += handle_none_type( args.standard_deviation ) + cmd += handle_none_type( args.radius ) + cmd += handle_none_type( args.threshold ) + cmd += ' %s' % args.which_outliers + cmd += ' %s' % args.randomj + cmd += handle_none_type( args.trials ) + cmd += handle_none_type( args.probability ) + cmd += handle_none_type( args.lammbda ) + cmd += handle_none_type( args.order, val_type='int' ) + cmd += handle_none_type( args.mean ) + cmd += handle_none_type( args.sigma ) + cmd += handle_none_type( args.min ) + cmd += handle_none_type( args.max ) + cmd += ' %s' % args.insertion + cmd += ' %s' % tmp_output_path + + proc = subprocess.Popen( args=cmd, stderr=tmp_stderr, stdout=tmp_stdout, shell=True ) + rc = proc.wait() + + # Handle execution errors. + if rc != 0: + error_message = imagej2_base_utils.get_stderr_exception( tmp_err, tmp_stderr, tmp_stdout ) + imagej2_base_utils.stop_err( error_message ) + # Handle processing errors. + if os.path.getsize( error_log ) > 0: + error_message = open( error_log, 'r' ).read() + imagej2_base_utils.stop_err( error_message ) + # Save the output image. + shutil.move( tmp_output_path, args.output ) + imagej2_base_utils.cleanup_before_exit( tmp_dir )
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/imagej2_noise.xml Fri Jun 19 16:59:22 2015 -0400 @@ -0,0 +1,169 @@ +<?xml version='1.0' encoding='UTF-8'?> +<tool id="imagej2_noise" name="Add or remove noise" version="1.0.0"> + <description>with ImageJ2</description> + <macros> + <import>imagej2_macros.xml</import> + <xml name="insertion_select"> + <param name="insertion" type="select" label="Insertion"> + <option value="additive" selected="True">Additive</option> + <option value="multiplicative">Multiplicative</option> + </param> + </xml> + </macros> + <expand macro="fiji_headless_requirements" /> + <command> +<![CDATA[ + python $__tool_directory__/imagej2_noise.py + --input "$input" + --input_datatype $input.ext + --noise $noise_cond.noise + #if $noise_cond.noise == 'add_specified_noise': + --standard_deviation $noise_cond.standard_deviation + #else if $noise_cond.noise == 'remove_outliers': + --radius $noise_cond.radius + --threshold $noise_cond.threshold + --which_outliers $noise_cond.which_outliers + #else if $noise_cond.noise == 'randomj': + --randomj $noise_cond.randomj_cond.randomj + #if $noise_cond.randomj_cond.randomj == 'randomj_binomial': + --trials $noise_cond.randomj_cond.trials + --probability $noise_cond.randomj_cond.probability + #else if $noise_cond.randomj_cond.randomj == 'randomj_exponential': + --lammbda $noise_cond.randomj_cond.lammbda + #else if $noise_cond.randomj_cond.randomj == 'randomj_gamma': + --order $noise_cond.randomj_cond.order + #else if $noise_cond.randomj_cond.randomj == 'randomj_gaussian': + --mean $noise_cond.randomj_cond.mean + --sigma $noise_cond.randomj_cond.sigma + #else if $noise_cond.randomj_cond.randomj == 'randomj_poisson': + --mean $noise_cond.randomj_cond.mean + #else if $noise_cond.randomj_cond.randomj == 'randomj_uniform': + --min $noise_cond.randomj_cond.min + --max $noise_cond.randomj_cond.max + #end if + --insertion $noise_cond.randomj_cond.insertion + #end if + --max_heap_size_type $set_max_heap_size.max_heap_size_type + --max_heap_size $set_max_heap_size.max_heap_size + --jython_script $__tool_directory__/jython_script.py + --output "$output" +]]> + </command> + <inputs> + <param format="bmp,eps,gif,jpg,pcx,pgm,png,psd,tiff" name="input" type="data" label="Select image"/> + <conditional name="noise_cond"> + <param name="noise" type="select" label="Noise"> + <option value="add_noise" selected="True">Add Random Noise</option> + <option value="add_specified_noise">Add Specified Noise</option> + <option value="salt_and_pepper">Salt and Pepper</option> + <option value="despeckle">Despeckle</option> + <option value="remove_outliers">Remove Outliers</option> + <option value="remove_nans">Remove NaNs</option> + <option value="rof_denoise">ROF Denoise</option> + <option value="randomj">RandomJ</option> + </param> + <when value="add_noise" /> + <when value="add_specified_noise"> + <param name="standard_deviation" type="float" value="25.0" label="Standard deviation" help="Floating point number"/> + </when> + <when value="salt_and_pepper" /> + <when value="despeckle" /> + <when value="remove_outliers"> + <param name="radius" type="float" value="2.0" label="Radius" help="pixels"/> + <param name="threshold" type="float" value="50.0" label="Threshold"/> + <param name="which_outliers" type="select" label="Which Outliers"> + <option value="bright" selected="True">Bright</option> + <option value="dark">Dark</option> + </param> + </when> + <when value="remove_nans" /> + <when value="randomj"> + <conditional name="randomj_cond"> + <param name="randomj" type="select" label="RandomJ"> + <option value="randomj_binomial" selected="True">RandomJ Binomial</option> + <option value="randomj_exponential">RandomJ Exponential</option> + <option value="randomj_gamma">RandomJ Gamma</option> + <option value="randomj_gaussian">RandomJ Gaussian</option> + <option value="randomj_poisson">RandomJ Poisson</option> + <option value="randomj_uniform">RandomJ Uniform</option> + </param> + <when value="randomj_binomial"> + <param name="trials" type="float" value="1.0" label="Trials"/> + <param name="probability" type="float" value="0.5" label="Probability"/> + <expand macro="insertion_select" /> + </when> + <when value="randomj_exponential"> + <param name="lammbda" type="float" value="0.5" label="Lambda"/> + <expand macro="insertion_select" /> + </when> + <when value="randomj_gamma"> + <param name="order" type="integer" value="1" label="Order"/> + <expand macro="insertion_select" /> + </when> + <when value="randomj_gaussian"> + <param name="mean" type="float" value="0.0" label="Mean"/> + <param name="sigma" type="float" value="1.0" label="Sigma"/> + <expand macro="insertion_select" /> + </when> + <when value="randomj_poisson"> + <param name="mean" type="float" value="1.0" label="Mean"/> + <expand macro="insertion_select" /> + </when> + <when value="randomj_uniform"> + <param name="min" type="float" value="0.0" label="Min"/> + <param name="max" type="float" value="1.0" label="Max"/> + <expand macro="insertion_select" /> + </when> + </conditional> + </when> + </conditional> + <expand macro="max_heap_size_type_conditional" /> + </inputs> + <outputs> + <data name="output" format_source="input" label="${tool.name} on ${on_string}: ${noise_cond.noise.replace( '_', ' ' )}" /> + </outputs> + <tests> + <test> + <param name="input" value="blobs.gif" /> + <param name="input_datatype" value="gif" /> + <param name="noise" value="add_specified_noise" /> + <output name="output" file="add_specified_noise.gif" /> + </test> + <test> + <param name="input" value="blobs.gif" /> + <param name="input_datatype" value="gif" /> + <param name="noise" value="despeckle" /> + <output name="output" file="despeckle.gif" /> + </test> + <test> + <param name="input" value="blobs.gif" /> + <param name="input_datatype" value="gif" /> + <param name="noise" value="remove_outliers" /> + <param name="radius" value="2.0" /> + <param name="threshold" value="50.0" /> + <param name="which_outliers" value="bright" /> + <output name="output" file="remove_outliers.gif" /> + </test> + </tests> + <help> +**What it does** + +<![CDATA[ +Adds noise to or removes noise from images. + +- **Add Random Noise** - Adds random noise to the image. The noise is Gaussian (normally) distributed with a mean of zero and standard deviation of 25. +- **Add Specified Noise** - Adds Gaussian noise with a mean of zero and a chosen standard deviation. +- **Salt and Pepper** - Adds salt and pepper noise to the image by randomly replacing 2.5% of the pixels with black pixels and 2.5% with white pixels. This command only works with 8-bit images. +- **Despeckle** - Replaces each pixel with the median value in its 3 × 3 neighborhood. This is a time consuming operation because for each pixel, the nine pixels in the 3 × 3 neighborhood must be sorted and the center pixel replaced with the median value (the fifth). +- **Remove Outliers** - Replaces a pixel by the median of the pixels in the surrounding if it deviates from the median by more than a certain value (the threshold). +- **Remove NaNs** - Replaces NaN (Not-a-Number) pixels in 32-bit images by the median of the neighbors inside the circular kernel area defined by Radius. It does not remove patches of NaNs larger than the kernel size, however. +- **RandonJ Binomial** - Contaminates image with random numbers generated using a binomial random variable +- **RandonJ Exponential** - Contaminates image with random numbers generated using an exponential random variable. +- **RandonJ Gamma** - Contaminates image with random numbers generated using a gamma random variable. +- **RandonJ Gaussian** - Contaminates image with random numbers generated using a Gaussian random variable. +- **RandonJ Poisson** - Contaminates image with random numbers generated using a Poisson random variable. +- **RandonJ Uniform** - Contaminates image with random numbers generated using a uniform random variable. +]]> + </help> + <expand macro="fiji_headless_citations" /> +</tool>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jython_script.py Fri Jun 19 16:59:22 2015 -0400 @@ -0,0 +1,90 @@ +import sys +from ij import IJ +from ij import ImagePlus + +def handle_error( error_log, msg ): + elh = open( error_log, 'wb' ) + elh.write( msg ) + elh.close() + +# 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 ] +# 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 + +# Open the input image file. +image_plus = IJ.openImage( input ) +bit_depth = image_plus.getBitDepth() +image_type = image_plus.getType() +# Create an ImagePlus object for the image. +image_plus_copy = image_plus.createImagePlus() +# Make a copy of the image. +image_processor_copy = image_plus.getProcessor().duplicate() +# Set the ImageProcessor on the duplicate ImagePlus object. +image_plus_copy.setProcessor( "image copy", image_processor_copy ) + +# Perform the analysis on the ImagePlus object. +if noise == '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" ) +elif noise == 'salt_and_pepper': + IJ.run( image_plus_copy, "Salt and Pepper", "" ) +elif noise == '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" ) +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 + handle_error( error_log, msg ) + error = True +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 ) + handle_error( error_log, msg ) + error = True +elif noise == 'randomj': + if randomj == 'randomj_binomial': + 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" ) + elif randomj == 'randomj_gamma': + 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" ) + elif randomj == 'randomj_poisson': + 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" ) + +if not error: + # Save the ImagePlus object as a new image. + IJ.saveAs( image_plus_copy, image_datatype, tmp_output_path )
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tool_dependencies.xml Fri Jun 19 16:59:22 2015 -0400 @@ -0,0 +1,6 @@ +<?xml version="1.0"?> +<tool_dependency> + <package name="fiji" version="20141125"> + <repository changeset_revision="7121a1ea4839" name="package_fiji_20141125" owner="iuc" toolshed="https://testtoolshed.g2.bx.psu.edu" /> + </package> +</tool_dependency>
