import jython_utils
import sys
from ij import IJ

# Fiji Jython interpreter implements Python 2.5 which does not
# provide support for argparse.
error_log = sys.argv[-5]
input = sys.argv[-4]
direction = sys.argv[-3]
tmp_output_path = sys.argv[-2]
output_datatype = sys.argv[-1]

# Open the input image file.
input_image_plus = IJ.openImage(input)

# Create a copy of the image.
input_image_plus_copy = input_image_plus.duplicate()
image_processor_copy = input_image_plus_copy.getProcessor()

try:
    # Run the command.
    IJ.run(input_image_plus_copy, direction, "")
    # Save the ImagePlus object as a new image.
    IJ.saveAs(input_image_plus_copy, output_datatype, tmp_output_path)
except Exception, e:
    jython_utils.handle_error(error_log, str(e))
Beispiel #2
0
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
        jython_utils.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)
        jython_utils.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",
input_image_plus = IJ.openImage( input )

# Create a copy of the image.
input_image_plus_copy = input_image_plus.duplicate()
image_processor_copy = input_image_plus_copy.getProcessor()

try:
    # Convert image to binary if necessary.
    if not image_processor_copy.isBinary():
        # Convert the image to binary grayscale.
        IJ.run( input_image_plus_copy, "Make Binary","iterations=1 count=1 edm=Overwrite do=Nothing" )
    # Set the options.
    if jython_utils.asbool( dark_background ):
        method_str = "%s dark" % method
    else:
        method_str = method
    IJ.setAutoThreshold( input_image_plus_copy, method_str )
    if display == "red":
        display_mode = "Red"
    elif display == "bw":
        display_mode = "Black & White"
    elif display == "over_under":
        display_mode = "Over/Under"
    IJ.setThreshold( input_image_plus_copy, threshold_min, threshold_max, display_mode )
    # Run the command.
    IJ.run( input_image_plus_copy, "threshold", "" )
    # Save the ImagePlus object as a new image.
    IJ.saveAs( input_image_plus_copy, output_datatype, tmp_output_path )
except Exception, e:
    jython_utils.handle_error( error_log, str( e ) )
Beispiel #4
0
    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
        jython_utils.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 )
        jython_utils.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" )