# HG changeset patch # User iuc # Date 1440614261 14400 # Node ID d26f11339f08859abc1295c760d5fb620de4d874 # Parent 66d9e595dff29e46e6dc40656dcadf751eee6da3 planemo upload commit 18df9e67efd4adafcde4eb9b62cd815e4afe9733-dirty diff -r 66d9e595dff2 -r d26f11339f08 imagej2_base_utils.py --- a/imagej2_base_utils.py Tue Aug 04 13:20:29 2015 -0400 +++ b/imagej2_base_utils.py Wed Aug 26 14:37:41 2015 -0400 @@ -86,21 +86,6 @@ 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 int( 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 = {} @@ -172,6 +157,7 @@ return ' %.1f' % val elif val_type == 'int': return ' %d' % val + return ' %s' % val def stop_err( msg ): sys.stderr.write( msg ) diff -r 66d9e595dff2 -r d26f11339f08 imagej2_macros.xml --- a/imagej2_macros.xml Tue Aug 04 13:20:29 2015 -0400 +++ b/imagej2_macros.xml Wed Aug 26 14:37:41 2015 -0400 @@ -1,11 +1,12 @@ - + 1.0 + fiji - + fiji javabridge @@ -53,33 +54,27 @@ + + + + + + --iterations $iterations --count $count --black_background $black_background --pad_edges_when_eroding $pad_edges_when_eroding - - - - - - - - - - - - - - - - - - - - --max_heap_size_type $set_max_heap_size.max_heap_size_type - --max_heap_size $set_max_heap_size.max_heap_size + +.. class:: warningmark + +This tool works on binary images, so other image types will automatically be converted to binary +before they are analyzed. This step is performed using the ImageJ2 **Make Binary** command with +the following settings: **Iterations:** 1, **Count:** 1, **Pad edges when eroding:** No. The tool +allows you to choose the **Black background** setting. If these settings are not appropriate, +first manually convert the image to binary using the **Convert to binary (black and white) with ImageJ2** +tool, which allows you to change them. diff -r 66d9e595dff2 -r d26f11339f08 imagej2_make_binary.py --- a/imagej2_make_binary.py Tue Aug 04 13:20:29 2015 -0400 +++ b/imagej2_make_binary.py Wed Aug 26 14:37:41 2015 -0400 @@ -14,8 +14,6 @@ parser.add_argument( '--black_background', dest='black_background', help='Black background' ) parser.add_argument( '--pad_edges_when_eroding', dest='pad_edges_when_eroding', help='Pad edges when eroding' ) 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', dest='output', help='Path to the output file' ) parser.add_argument( '--output_datatype', dest='output_datatype', help='Datatype of the output image' ) args = parser.parse_args() @@ -26,8 +24,6 @@ # 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.output_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' ) @@ -36,7 +32,7 @@ # 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 ) +cmd = imagej2_base_utils.get_base_command_imagej2( None, jython_script=args.jython_script ) if cmd is None: imagej2_base_utils.stop_err( "ImageJ not found!" ) cmd += ' %s' % error_log diff -r 66d9e595dff2 -r d26f11339f08 imagej2_make_binary.xml --- a/imagej2_make_binary.xml Tue Aug 04 13:20:29 2015 -0400 +++ b/imagej2_make_binary.xml Wed Aug 26 14:37:41 2015 -0400 @@ -1,38 +1,27 @@ - + (black and white) with ImageJ2 imagej2_macros.xml - + - - - - - - - - - - + diff -r 66d9e595dff2 -r d26f11339f08 jython_script.py --- a/jython_script.py Tue Aug 04 13:20:29 2015 -0400 +++ b/jython_script.py Wed Aug 26 14:37:41 2015 -0400 @@ -1,40 +1,36 @@ import jython_utils import sys from ij import IJ -from ij import ImagePlus # Fiji Jython interpreter implements Python 2.5 which does not # provide support for argparse. error_log = sys.argv[ -8 ] input = sys.argv[ -7 ] -iterations = sys.argv[ -6 ] -count = sys.argv[ -5 ] -black_background = sys.argv[ -4 ] -pad_edges_when_eroding = sys.argv[ -3 ] +iterations = int( sys.argv[ -6 ] ) +count = int( sys.argv[ -5 ] ) +black_background = jython_utils.asbool( sys.argv[ -4 ] ) +pad_edges_when_eroding = jython_utils.asbool( 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 ) -bit_depth = input_image_plus.getBitDepth() -image_type = input_image_plus.getType() # Create a copy of the image. -input_image_plus_copy = input_image_plus.createImagePlus() -image_processor_copy = input_image_plus.getProcessor().duplicate() -input_image_plus_copy.setProcessor( "iCopy", image_processor_copy ) +input_image_plus_copy = input_image_plus.duplicate() +image_processor_copy = input_image_plus_copy.getProcessor() try: - options = [ "iterations=&iterations" "count=&count" ] - if black_background == "yes": - options.append( "black" ) - if pad_edges_when_eroding == "yes": - options.append( "pad" ) - # The following have no affect within this tool, but are necessary. - options.append( "edm=Overwrite" ) - options.append( "do=Nothing" ) + # Set binary options. + options = jython_utils.get_binary_options( black_background=black_background, + iterations=iterations, + count=count, + pad_edges_when_eroding=pad_edges_when_eroding ) + IJ.run( input_image_plus_copy, "Options...", options ) + # Run the command. - IJ.run( input_image_plus_copy, "Make Binary", " ".join( options ) ) + IJ.run( input_image_plus_copy, "Make Binary", "" ) + # Save the ImagePlus object as a new image. IJ.saveAs( input_image_plus_copy, output_datatype, tmp_output_path ) except Exception, e: diff -r 66d9e595dff2 -r d26f11339f08 jython_utils.py --- a/jython_utils.py Tue Aug 04 13:20:29 2015 -0400 +++ b/jython_utils.py Wed Aug 26 14:37:41 2015 -0400 @@ -4,6 +4,9 @@ IMAGE_PLUS_IMAGE_TYPE_FIELD_VALUES = { '0':'GRAY8', '1':'GRAY16', '2':'GRAY32', '3':'COLOR_256', '4':'COLOR_RGB' } +def asbool( val ): + return str( val ).lower() in [ 'yes', 'true' ] + def convert_before_saving_as_tiff( image_plus ): # The bUnwarpJ plug-in produces TIFF image stacks consisting of 3 # slices which can be viewed in ImageJ. The 3 slices are: 1) the @@ -26,6 +29,14 @@ IJ.saveAs( image_plus, 'png', tmp_out_png_path ) return IJ.openImage( tmp_out_png_path ) +def get_binary_options( black_background, iterations=1, count=1, pad_edges_when_eroding='no' ): + options = [ 'edm=Overwrite', 'iterations=%d' % iterations, 'count=%d' % count ] + if asbool( pad_edges_when_eroding ): + options.append( 'pad' ) + if asbool( black_background ): + options.append( "black" ) + return " ".join( options ) + def get_display_image_type( image_type ): return IMAGE_PLUS_IMAGE_TYPE_FIELD_VALUES.get( str( image_type ), None )