Previous changeset 0:a84f2cbf091b (2019-09-17) Next changeset 2:49e29abe0fce (2023-11-05) |
Commit message:
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 2afb24f3c81d625312186750a714d702363012b5" |
modified:
imagej2_adjust_threshold_binary_jython_script.py imagej2_analyze_particles_binary_jython_script.py imagej2_analyze_skeleton_jython_script.py imagej2_binary_to_edm_jython_script.py imagej2_create_image_jython_script.py imagej2_enhance_contrast_jython_script.py imagej2_find_edges_jython_script.py imagej2_find_maxima_jython_script.py imagej2_macros.xml imagej2_make_binary_jython_script.py imagej2_math_jython_script.py imagej2_noise_jython_script.py imagej2_shadows_jython_script.py imagej2_sharpen.xml imagej2_sharpen_jython_script.py imagej2_skeletonize3d_jython_script.py imagej2_smooth_jython_script.py imagej2_watershed_binary_jython_script.py test-data/analyze_particles_masks.gif test-data/analyze_particles_nothing.tabular test-data/analyze_particles_outlines.gif test-data/basic.tabular test-data/blobs_black_edm.gif test-data/blobs_edm.gif test-data/blobs_equalize.gif test-data/blobs_find_edges.gif test-data/blobs_log.gif test-data/blobs_min.gif test-data/blobs_multiply.gif test-data/blobs_normalize.gif test-data/blobs_northwest.gif test-data/blobs_saturate.gif test-data/blobs_segmented.gif test-data/blobs_single_points.gif test-data/blobs_square.gif test-data/blobs_tolerance.gif test-data/blobs_watershed_binary.gif test-data/elastic_trans_registered_source1.png test-data/largest_shortest_path_basic.tabular test-data/raw_trans_registered_source1.png test-data/registered_source1.png test-data/registered_source2.png test-data/registered_target1.png test-data/registered_target2.png test-data/skeletonized_blobs.gif |
added:
test-data/source_elastic_transformation_out.txt test-data/target_elastic_transformation_out.txt |
removed:
imagej2_adjust_threshold_binary.py imagej2_analyze_particles_binary.py imagej2_analyze_skeleton.py imagej2_base_utils.py imagej2_binary_to_edm.py imagej2_bunwarpj_adapt_transform.py imagej2_bunwarpj_align.py imagej2_bunwarpj_align_jython_script.py imagej2_bunwarpj_compare_elastic.py imagej2_bunwarpj_compare_elastic_raw.py imagej2_bunwarpj_compare_raw.py imagej2_bunwarpj_compose_elastic.py imagej2_bunwarpj_compose_raw.py imagej2_bunwarpj_compose_raw_elastic.py imagej2_bunwarpj_convert_to_raw.py imagej2_bunwarpj_elastic_transform.py imagej2_bunwarpj_elastic_transform_jython_script.py imagej2_bunwarpj_raw_transform.py imagej2_bunwarpj_raw_transform_jython_script.py imagej2_create_image.py imagej2_enhance_contrast.py imagej2_find_edges.py imagej2_find_maxima.py imagej2_make_binary.py imagej2_math.py imagej2_noise.py imagej2_shadows.py imagej2_sharpen.py imagej2_skeletonize3d.py imagej2_smooth.py imagej2_watershed_binary.py jython_utils.py |
b |
diff -r a84f2cbf091b -r 4c43ba752312 imagej2_adjust_threshold_binary.py --- a/imagej2_adjust_threshold_binary.py Tue Sep 17 17:08:08 2019 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 |
b |
@@ -1,63 +0,0 @@ -#!/usr/bin/env python -import argparse -import os -import shutil -import subprocess -import tempfile -import imagej2_base_utils - -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( '--threshold_min', dest='threshold_min', type=float, help='Minimum threshold value' ) -parser.add_argument( '--threshold_max', dest='threshold_max', type=float, help='Maximum threshold value' ) -parser.add_argument( '--method', dest='method', help='Threshold method' ) -parser.add_argument( '--display', dest='display', help='Display mode' ) -parser.add_argument( '--black_background', dest='black_background', help='Black background' ) -parser.add_argument( '--stack_histogram', dest='stack_histogram', help='Stack histogram' ) -parser.add_argument( '--jython_script', dest='jython_script', help='Path to the Jython script' ) -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() - -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.output_datatype ) -# 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( None, 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 += ' %.3f' % args.threshold_min -cmd += ' %.3f' % args.threshold_max -cmd += ' %s' % args.method -cmd += ' %s' % args.display -cmd += ' %s' % args.black_background -cmd += ' %s' % args.stack_histogram -cmd += ' %s' % tmp_output_path -cmd += ' %s' % args.output_datatype -# Run the command. -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_out, 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 ) |
b |
diff -r a84f2cbf091b -r 4c43ba752312 imagej2_adjust_threshold_binary_jython_script.py --- a/imagej2_adjust_threshold_binary_jython_script.py Tue Sep 17 17:08:08 2019 -0400 +++ b/imagej2_adjust_threshold_binary_jython_script.py Mon Sep 28 16:38:24 2020 +0000 |
[ |
@@ -1,49 +1,46 @@ -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[ -10 ] -input = sys.argv[ -9 ] -threshold_min = float( sys.argv[ -8 ] ) -threshold_max = float( sys.argv[ -7 ] ) -method = sys.argv[ -6 ] -display = sys.argv[ -5 ] -black_background = jython_utils.asbool( sys.argv[ -4 ] ) +error_log = sys.argv[-10] +input_file = sys.argv[-9] +threshold_min = float(sys.argv[-8]) +threshold_max = float(sys.argv[-7]) +method = sys.argv[-6] +display = sys.argv[-5] +black_background = sys.argv[-4] == "yes" # TODO: this is not being used. -stack_histogram = jython_utils.asbool( sys.argv[ -3 ] ) -tmp_output_path = sys.argv[ -2 ] -output_datatype = sys.argv[ -1 ] +stack_histogram = sys.argv[-3] == "yes" +output_filename = sys.argv[-2] +output_datatype = sys.argv[-1] # Open the input image file. -input_image_plus = IJ.openImage( input ) +input_image_plus = IJ.openImage(input_file) # 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 black_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 ) ) +# 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 black_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, output_filename) |
b |
diff -r a84f2cbf091b -r 4c43ba752312 imagej2_analyze_particles_binary.py --- a/imagej2_analyze_particles_binary.py Tue Sep 17 17:08:08 2019 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 |
b |
@@ -1,81 +0,0 @@ -#!/usr/bin/env python -import argparse -import os -import shutil -import subprocess -import tempfile -import imagej2_base_utils - -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( '--black_background', dest='black_background', help='Black background' ) -parser.add_argument( '--size', dest='size', help='Size (pixel^2)' ) -parser.add_argument( '--circularity_min', dest='circularity_min', type=float, help='Circularity minimum' ) -parser.add_argument( '--circularity_max', dest='circularity_max', type=float, help='Circularity maximum' ) -parser.add_argument( '--show', dest='show', help='Show' ) -parser.add_argument( '--display_results', dest='display_results', help='Display results' ) -parser.add_argument( '--all_results', dest='all_results', help='All results' ) -parser.add_argument( '--exclude_edges', dest='exclude_edges', help='Exclude edges' ) -parser.add_argument( '--include_holes', dest='include_holes', help='Include holes' ) -parser.add_argument( '--jython_script', dest='jython_script', help='Path to the Jython script' ) -parser.add_argument( '--results', dest='results', default=None, help='Path to the output results file' ) -parser.add_argument( '--output', dest='output', default=None, help='Path to the output image file' ) -parser.add_argument( '--output_datatype', dest='output_datatype', default='data', help='Datatype of the output image' ) -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 ) -if args.output is None: - tmp_output_path = None -else: - tmp_output_path = imagej2_base_utils.get_temporary_image_path( tmp_dir, args.output_datatype ) - -# 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( None, 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.black_background -cmd += ' %s' % args.size -cmd += ' %.3f' % args.circularity_min -cmd += ' %.3f' % args.circularity_max -cmd += ' %s' % args.show -cmd += ' %s' % args.display_results -cmd += '%s' % imagej2_base_utils.handle_none_type( args.all_results, val_type='str' ) -cmd += ' %s' % args.exclude_edges -cmd += ' %s' % args.include_holes -cmd += '%s' % imagej2_base_utils.handle_none_type( tmp_output_path, val_type='str' ) -cmd += ' %s' % args.output_datatype -cmd += '%s' % imagej2_base_utils.handle_none_type( args.results, val_type='str' ) - -# Run the command. -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_out, 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 ) - -if tmp_output_path is not None: - # Save the output image. - shutil.move( tmp_output_path, args.output ) -imagej2_base_utils.cleanup_before_exit( tmp_dir ) |
b |
diff -r a84f2cbf091b -r 4c43ba752312 imagej2_analyze_particles_binary_jython_script.py --- a/imagej2_analyze_particles_binary_jython_script.py Tue Sep 17 17:08:08 2019 -0400 +++ b/imagej2_analyze_particles_binary_jython_script.py Mon Sep 28 16:38:24 2020 +0000 |
[ |
@@ -1,72 +1,74 @@ -import jython_utils import sys + from ij import IJ from ij.plugin.filter import Analyzer + +OPTIONS = ['edm=Overwrite', 'iterations=1', 'count=1'] + # Fiji Jython interpreter implements Python 2.5 which does not # provide support for argparse. -error_log = sys.argv[ -14 ] -input = sys.argv[ -13 ] -black_background = jython_utils.asbool( sys.argv[ -12 ] ) -size = sys.argv[ -11 ] -circularity_min = float( sys.argv[ -10 ] ) -circularity_max = float( sys.argv[ -9 ] ) -show = sys.argv[ -8 ] -display_results = jython_utils.asbool( sys.argv[ -7 ] ) -all_results = jython_utils.asbool( sys.argv[ -6 ] ) -exclude_edges = jython_utils.asbool( sys.argv[ -5 ] ) -include_holes = jython_utils.asbool( sys.argv[ -4 ] ) -tmp_output_path = sys.argv[ -3 ] -output_datatype = sys.argv[ -2 ] -results_path = sys.argv[ -1 ] +error_log = sys.argv[-14] +input_file = sys.argv[-13] +black_background = sys.argv[-12] == "yes" +size = sys.argv[-11] +circularity_min = float(sys.argv[-10]) +circularity_max = float(sys.argv[-9]) +show = sys.argv[-8] +display_results = sys.argv[-7] == "yes" +all_results = sys.argv[-6] == "yes" +exclude_edges = sys.argv[-5] == "yes" +include_holes = sys.argv[-4] == "yes" +output_filename = sys.argv[-3] +output_datatype = sys.argv[-2] +results_path = sys.argv[-1] # Open the input image file. -input_image_plus = IJ.openImage( input ) +input_image_plus = IJ.openImage(input_file) # Create a copy of the image. input_image_plus_copy = input_image_plus.duplicate() image_processor_copy = input_image_plus_copy.getProcessor() -analyzer = Analyzer( input_image_plus_copy ) +analyzer = Analyzer(input_image_plus_copy) -try: - # Set binary options. - options = jython_utils.get_binary_options( black_background=black_background ) - IJ.run( input_image_plus_copy, "Options...", options ) +# Set binary options. +options_list = OPTIONS +if black_background: + options_list.append("black") +options = " ".join(options_list) +IJ.run(input_image_plus_copy, "Options...", options) - # 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", "" ) +if not image_processor_copy.isBinary(): + # Convert the image to binary grayscale. + IJ.run(input_image_plus_copy, "Make Binary", "") - # Set the options. - options = [ 'size=%s' % size ] - circularity_str = '%.3f-%.3f' % ( circularity_min, circularity_max ) - options.append( 'circularity=%s' % circularity_str ) - if show.find( '_' ) >= 0: - show_str = '[%s]' % show.replace( '_', ' ' ) - else: - show_str = show - options.append( 'show=%s' % show_str ) - if display_results: - options.append( 'display' ) - if not all_results: - options.append( 'summarize' ) - if exclude_edges: - options.append( 'exclude' ) - if include_holes: - options.append( 'include' ) - # Always run "in_situ". - options.append( 'in_situ' ) +# Set the options. +options = ['size=%s' % size] +circularity_str = '%.3f-%.3f' % (circularity_min, circularity_max) +options.append('circularity=%s' % circularity_str) +if show.find('_') >= 0: + show_str = '[%s]' % show.replace('_', ' ') +else: + show_str = show +options.append('show=%s' % show_str) +if display_results: + options.append('display') + if not all_results: + options.append('summarize') +if exclude_edges: + options.append('exclude') +if include_holes: + options.append('include') +# Always run "in_situ". +options.append('in_situ') - # Run the command. - IJ.run( input_image_plus_copy, "Analyze Particles...", " ".join( options ) ) +# Run the command. +IJ.run(input_image_plus_copy, "Analyze Particles...", " ".join(options)) - # Save outputs. - if tmp_output_path not in [ None, 'None' ]: - # Save the ImagePlus object as a new image. - IJ.saveAs( input_image_plus_copy, output_datatype, tmp_output_path ) - if display_results and results_path not in [ None, 'None' ]: - results_table = analyzer.getResultsTable() - results_table.saveAs( results_path ) -except Exception, e: - jython_utils.handle_error( error_log, str( e ) ) +# Save outputs. +if len(output_filename) > 0: + # Save the ImagePlus object as a new image. + IJ.saveAs(input_image_plus_copy, output_datatype, output_filename) +if display_results and len(results_path) > 0: + results_table = analyzer.getResultsTable() + results_table.saveAs(results_path) |
b |
diff -r a84f2cbf091b -r 4c43ba752312 imagej2_analyze_skeleton.py --- a/imagej2_analyze_skeleton.py Tue Sep 17 17:08:08 2019 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 |
b |
@@ -1,61 +0,0 @@ -#!/usr/bin/env python -import argparse -import os -import shutil -import subprocess -import tempfile -import imagej2_base_utils - -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( '--black_background', dest='black_background', help='Black background' ) -parser.add_argument( '--prune_cycle_method', dest='prune_cycle_method', default='none', help='Prune cycle method' ) -parser.add_argument( '--prune_ends', dest='prune_ends', default='no', help='Prune ends' ) -parser.add_argument( '--calculate_largest_shortest_path', dest='calculate_largest_shortest_path', default='no', help='Calculate largest shortest path' ) -parser.add_argument( '--show_detailed_info', dest='show_detailed_info', default='no', help='Show detailed info' ) -parser.add_argument( '--jython_script', dest='jython_script', help='Path to the Jython script' ) -parser.add_argument( '--output', dest='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 ) - -# 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( None, 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.black_background -cmd += ' %s' % args.prune_cycle_method -cmd += ' %s' % args.prune_ends -cmd += ' %s' % args.calculate_largest_shortest_path -cmd += ' %s' % args.show_detailed_info -cmd += ' %s' % args.output - -# Run the command. -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_out, 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 ) - -imagej2_base_utils.cleanup_before_exit( tmp_dir ) |
b |
diff -r a84f2cbf091b -r 4c43ba752312 imagej2_analyze_skeleton_jython_script.py --- a/imagej2_analyze_skeleton_jython_script.py Tue Sep 17 17:08:08 2019 -0400 +++ b/imagej2_analyze_skeleton_jython_script.py Mon Sep 28 16:38:24 2020 +0000 |
[ |
b"@@ -1,147 +1,148 @@\n-import jython_utils\n import math\n import sys\n+\n from ij import IJ\n from sc.fiji.analyzeSkeleton import AnalyzeSkeleton_\n \n-BASIC_NAMES = [ 'Branches', 'Junctions', 'End-point Voxels',\n- 'Junction Voxels', 'Slab Voxels', 'Average branch length',\n- 'Triple Points', 'Quadruple Points', 'Maximum Branch Length' ]\n-DETAIL_NAMES = [ 'Skeleton ID', 'Branch length', 'V1 x', 'V1 y', 'V1 z', 'V2 x',\n- 'V2 y', 'V2 z', 'Euclidean distance' ]\n+BASIC_NAMES = ['Branches', 'Junctions', 'End-point Voxels',\n+ 'Junction Voxels', 'Slab Voxels', 'Average branch length',\n+ 'Triple Points', 'Quadruple Points', 'Maximum Branch Length']\n+DETAIL_NAMES = ['Skeleton ID', 'Branch length', 'V1 x', 'V1 y', 'V1 z', 'V2 x',\n+ 'V2 y', 'V2 z', 'Euclidean distance']\n+OPTIONS = ['edm=Overwrite', 'iterations=1', 'count=1']\n+\n \n-def get_euclidean_distance( vertex1, vertex2 ):\n- x1, y1, z1 = get_points( vertex1 )\n- x2, y2, z2 = get_points( vertex2 )\n- return math.sqrt( math.pow( ( x2 - x1 ), 2 ) +\n- math.pow( ( y2 - y1 ), 2 ) +\n- math.pow( ( z2 - z1 ), 2 ) )\n+def get_euclidean_distance(vertex1, vertex2):\n+ x1, y1, z1 = get_points(vertex1)\n+ x2, y2, z2 = get_points(vertex2)\n+ return math.sqrt(math.pow((x2 - x1), 2) + math.pow((y2 - y1), 2) + math.pow((z2 - z1), 2))\n \n-def get_graph_length( graph ):\n+\n+def get_graph_length(graph):\n length = 0\n for edge in graph.getEdges():\n length = length + edge.getLength()\n return length\n \n-def get_points( vertex ):\n+\n+def get_points(vertex):\n # An array of Point, which has attributes x,y,z.\n- point = vertex.getPoints()[ 0 ]\n+ point = vertex.getPoints()[0]\n return point.x, point.y, point.z\n- \n-def get_sorted_edge_lengths( graph ):\n+\n+\n+def get_sorted_edge_lengths(graph):\n # Return graph edges sorted from longest to shortest.\n edges = graph.getEdges()\n- edges = sorted( edges, key=lambda edge: edge.getLength(), reverse=True )\n+ edges = sorted(edges, key=lambda edge: edge.getLength(), reverse=True)\n return edges\n \n-def get_sorted_graph_lengths( result ):\n+\n+def get_sorted_graph_lengths(result):\n # Get the separate graphs (skeletons).\n graphs = result.getGraph()\n # Sort graphs from longest to shortest.\n- graphs = sorted( graphs, key=lambda g: get_graph_length( g ), reverse=True )\n+ graphs = sorted(graphs, key=lambda g: get_graph_length(g), reverse=True)\n return graphs\n \n-def save( result, output, show_detailed_info, calculate_largest_shortest_path, sep='\\t' ):\n- num_trees = int( result.getNumOfTrees() )\n- outf = open( output, 'wb' )\n- outf.write( '# %s\\n' % sep.join( BASIC_NAMES ) )\n- for index in range( num_trees ):\n- outf.write( '%d%s' % ( result.getBranches()[ index ], sep ) )\n- outf.write( '%d%s' % ( result.getJunctions()[ index ], sep ) )\n- outf.write( '%d%s' % ( result.getEndPoints()[ index ], sep ) )\n- outf.write( '%d%s' % ( result.getJunctionVoxels()[ index ], sep ) )\n- outf.write( '%d%s' % ( result.getSlabs()[ index ], sep ) )\n- outf.write( '%.3f%s' % ( result.getAverageBranchLength()[ index ], sep ) )\n- outf.write( '%d%s' % ( result.getTriples()[ index ], sep ) )\n- outf.write( '%d%s' % ( result.getQuadruples()[ index ], sep ) )\n- outf.write( '%.3f' % result.getMaximumBranchLength()[ index ] )\n+\n+def save(result, output, show_detailed_info, calculate_largest_shortest_path, sep='\\t'):\n+ num_trees = int(result.getNumOfTrees())\n+ outf = open(output, 'wb')\n+ outf.write('# %s\\n' % sep.join(BASIC_NAMES))\n+ for index in range(num_trees):\n+ outf.write('%d%s' % (result.getBranches()[index], sep))\n+ outf.write('%d%s' % (result.getJunctions()[index], sep))\n+ outf.write('%d%s' % (result.getEndPoints()[index], sep))\n+ outf.write('%d%s' % (result.getJunctionVoxels()[index], sep))\n+ "..b'sep, sep))\n+ outf.write(\' %s\' % sep)\n+ outf.write(\' %s\' % sep)\n+ outf.write(\' \\n\')\n else:\n- outf.write( \'\\n\' )\n+ outf.write(\'\\n\')\n outf.close()\n \n+\n # Fiji Jython interpreter implements Python 2.5 which does not\n # provide support for argparse.\n-error_log = sys.argv[ -8 ]\n-input = sys.argv[ -7 ]\n-black_background = jython_utils.asbool( sys.argv[ -6 ] )\n-prune_cycle_method = sys.argv[ -5 ]\n-prune_ends = jython_utils.asbool( sys.argv[ -4 ] )\n-calculate_largest_shortest_path = jython_utils.asbool( sys.argv[ -3 ] )\n+error_log = sys.argv[-8]\n+input = sys.argv[-7]\n+black_background = sys.argv[-6] == "yes"\n+prune_cycle_method = sys.argv[-5]\n+prune_ends = sys.argv[-4] == "yes"\n+calculate_largest_shortest_path = sys.argv[-3] == "yes"\n if calculate_largest_shortest_path:\n- BASIC_NAMES.extend( [ \'Longest Shortest Path\', \'spx\', \'spy\', \'spz\' ] )\n- DETAIL_NAMES.extend( [ \' \', \' \', \' \', \' \' ] )\n-show_detailed_info = jython_utils.asbool( sys.argv[ -2 ] )\n-output = sys.argv[ -1 ]\n+ BASIC_NAMES.extend([\'Longest Shortest Path\', \'spx\', \'spy\', \'spz\'])\n+ DETAIL_NAMES.extend([\' \', \' \', \' \', \' \'])\n+show_detailed_info = sys.argv[-2] == "yes"\n+output = sys.argv[-1]\n \n # Open the input image file.\n-input_image_plus = IJ.openImage( input )\n+input_image_plus = IJ.openImage(input)\n \n # Create a copy of the image.\n input_image_plus_copy = input_image_plus.duplicate()\n image_processor_copy = input_image_plus_copy.getProcessor()\n \n-try:\n- # Set binary options.\n- options = jython_utils.get_binary_options( black_background=black_background )\n- IJ.run( input_image_plus_copy, "Options...", options )\n+# Set binary options.\n+options_list = OPTIONS\n+if black_background:\n+ options_list.append("black")\n+options = " ".join(options_list)\n+IJ.run(input_image_plus_copy, "Options...", options)\n \n- # Convert image to binary if necessary.\n- if not image_processor_copy.isBinary():\n- IJ.run( input_image_plus_copy, "Make Binary", "" )\n+# Convert image to binary if necessary.\n+if not image_processor_copy.isBinary():\n+ IJ.run(input_image_plus_copy, "Make Binary", "")\n \n- # Run AnalyzeSkeleton\n- analyze_skeleton = AnalyzeSkeleton_()\n- analyze_skeleton.setup( "", input_image_plus_copy )\n- if prune_cycle_method == \'none\':\n- prune_index = analyze_skeleton.NONE\n- elif prune_cycle_method == \'shortest_branch\':\n- prune_index = analyze_skeleton.SHORTEST_BRANCH\n- elif prune_cycle_method == \'lowest_intensity_voxel\':\n- prune_index = analyze_skeleton.LOWEST_INTENSITY_VOXEL\n- elif prune_cycle_method == \'lowest_intensity_branch\':\n- prune_index = analyze_skeleton.LOWEST_INTENSITY_BRANCH\n- result = analyze_skeleton.run( prune_index,\n- prune_ends,\n- calculate_largest_shortest_path,\n- input_image_plus_copy,\n- True,\n- True )\n- # Save the results.\n- save( result, output, show_detailed_info, calculate_largest_shortest_path )\n-except Exception, e:\n- jython_utils.handle_error( error_log, str( e ) )\n+# Run AnalyzeSkeleton\n+analyze_skeleton = AnalyzeSkeleton_()\n+analyze_skeleton.setup("", input_image_plus_copy)\n+if prune_cycle_method == \'none\':\n+ prune_index = analyze_skeleton.NONE\n+elif prune_cycle_method == \'shortest_branch\':\n+ prune_index = analyze_skeleton.SHORTEST_BRANCH\n+elif prune_cycle_method == \'lowest_intensity_voxel\':\n+ prune_index = analyze_skeleton.LOWEST_INTENSITY_VOXEL\n+elif prune_cycle_method == \'lowest_intensity_branch\':\n+ prune_index = analyze_skeleton.LOWEST_INTENSITY_BRANCH\n+result = analyze_skeleton.run(prune_index, prune_ends, calculate_largest_shortest_path, input_image_plus_copy, True, True)\n+# Save the results.\n+save(result, output, show_detailed_info, calculate_largest_shortest_path)\n' |
b |
diff -r a84f2cbf091b -r 4c43ba752312 imagej2_base_utils.py --- a/imagej2_base_utils.py Tue Sep 17 17:08:08 2019 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 |
[ |
@@ -1,169 +0,0 @@ -import os -import shutil -import sys -import tempfile - -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 jvm_memory in [None, 'None']: - jvm_memory_str = '' - else: - jvm_memory_str = '-Xmx%s' % jvm_memory - # The following bunwarpj_base_cmd string will look something like this: - # "java %s -cp $JAR_DIR/ij-1.49k.jar:$PLUGINS_DIR/bUnwarpJ_-2.6.1.jar \ - # bunwarpj.bUnwarpJ_" % (jvm_memory_str) - # See the bunwarpj.sh script for the fiji 20151222 - # bioconda recipe in github. - bunwarpj_base_cmd = "bunwarpj %s" % jvm_memory_str - return bunwarpj_base_cmd - - -def get_base_command_imagej2(memory_size=None, macro=None, jython_script=None): - imagej2_executable = get_imagej2_executable() - if imagej2_executable is None: - return None - cmd = '%s --ij2 --headless --debug' % 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 %s' % os.path.abspath(jython_script) - return cmd - - -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, but our bioconda recipe allows us to do this. - """ - return 'ImageJ' - - -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_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_out, tmp_stdout, include_stdout=False): - 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() - if include_stdout: - tmp_stdout = open(tmp_out, 'rb') - stdout_str = '' - buffsize = BUFF_SIZE - try: - while True: - stdout_str += tmp_stdout.read(buffsize) - if not stdout_str or len(stdout_str) % buffsize != 0: - break - except OverflowError: - pass - tmp_stdout.close() - if include_stdout: - return 'STDOUT\n%s\n\nSTDERR\n%s\n' % (stdout_str, stderr_str) - return 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 handle_none_type(val, val_type='float'): - if val is None: - return ' None' - else: - if val_type == 'float': - return ' %.3f' % val - elif val_type == 'int': - return ' %d' % val - return ' %s' % val - - -def stop_err(msg): - sys.stderr.write(msg) - sys.exit(1) |
b |
diff -r a84f2cbf091b -r 4c43ba752312 imagej2_binary_to_edm.py --- a/imagej2_binary_to_edm.py Tue Sep 17 17:08:08 2019 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 |
b |
@@ -1,65 +0,0 @@ -#!/usr/bin/env python -import argparse -import os -import shutil -import subprocess -import tempfile -import imagej2_base_utils - -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( '--iterations', dest='iterations', type=int, help='Iterations' ) -parser.add_argument( '--count', dest='count', type=int, help='Count' ) -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( '--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() - -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.output_datatype ) - -# 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( None, 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 += ' %d' % args.iterations -cmd += ' %d' % args.count -cmd += ' %s' % args.black_background -cmd += ' %s' % args.pad_edges_when_eroding -cmd += ' %s' % tmp_output_path -cmd += ' %s' % args.output_datatype - -# Run the command. -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_out, 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 ) |
b |
diff -r a84f2cbf091b -r 4c43ba752312 imagej2_binary_to_edm_jython_script.py --- a/imagej2_binary_to_edm_jython_script.py Tue Sep 17 17:08:08 2019 -0400 +++ b/imagej2_binary_to_edm_jython_script.py Mon Sep 28 16:38:24 2020 +0000 |
[ |
@@ -1,44 +1,40 @@ -import jython_utils import sys + from ij import IJ -from ij import ImagePlus -from ij.plugin.filter import Analyzer -from ij.plugin.filter import EDM # Fiji Jython interpreter implements Python 2.5 which does not # provide support for argparse. -error_log = sys.argv[ -8 ] -input = sys.argv[ -7 ] -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 ] +error_log = sys.argv[-8] +input_file = sys.argv[-7] +iterations = int(sys.argv[-6]) +count = int(sys.argv[-5]) +black_background = sys.argv[-4] == "yes" +pad_edges_when_eroding = sys.argv[-3] == "yes" +output_filename = sys.argv[-2] +output_datatype = sys.argv[-1] # Open the input image file. -input_image_plus = IJ.openImage( input ) +input_image_plus = IJ.openImage(input_file) # Create a copy of the image. input_image_plus_copy = input_image_plus.duplicate() image_processor_copy = input_image_plus_copy.getProcessor() -try: - # 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 ) +# Set binary options. +options_list = ['edm=Overwrite', 'iterations=%d' % iterations, 'count=%d' % count] +if black_background: + options_list.append("black") +if pad_edges_when_eroding: + options_list.append("pad") +options = " ".join(options_list) +IJ.run(input_image_plus_copy, "Options...", options) - # 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", "" ) +# 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", "") - # Run the command. - IJ.run( input_image_plus_copy, "Distance Map", "" ) - # 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 ) ) +# Run the command. +IJ.run(input_image_plus_copy, "Distance Map", "") +# Save the ImagePlus object as a new image. +IJ.saveAs(input_image_plus_copy, output_datatype, output_filename) |
b |
diff -r a84f2cbf091b -r 4c43ba752312 imagej2_bunwarpj_adapt_transform.py --- a/imagej2_bunwarpj_adapt_transform.py Tue Sep 17 17:08:08 2019 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 |
b |
@@ -1,65 +0,0 @@ -#!/usr/bin/env python -import argparse -import subprocess -import tempfile -import imagej2_base_utils - -# Parse Command Line. -parser = argparse.ArgumentParser() -parser.add_argument( '--source_image', dest='source_image', help='Source image' ) -parser.add_argument( '--source_image_format', dest='source_image_format', help='Source image format' ) -parser.add_argument( '--target_image', dest='target_image', help='Target image' ) -parser.add_argument( '--target_image_format', dest='target_image_format', help='Target image format' ) -parser.add_argument( '--input_elastic_transformation', dest='input_elastic_transformation', help='Input elastic transformation matrix' ) -parser.add_argument( '--image_size_factor', dest='image_size_factor', type=float, help='Image size factor' ) -parser.add_argument( '--output', dest='output', help='Warping index' ) - -args = parser.parse_args() - -tmp_dir = imagej2_base_utils.get_temp_dir() -source_image_path = imagej2_base_utils.get_input_image_path( tmp_dir, args.source_image, args.source_image_format ) -target_image_path = imagej2_base_utils.get_input_image_path( tmp_dir, args.target_image, args.target_image_format ) -input_elastic_transformation_path = imagej2_base_utils.get_input_image_path( tmp_dir, args.input_elastic_transformation, 'txt' ) - -# 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' ) - -def is_power2( val ): - if val < 0: - return False - if val < 1: - val = 1.0 / val - val = int( val ) - return ( ( val & ( val - 1 ) ) == 0 ) - -# Build the command line to adapt the transformation. -cmd = imagej2_base_utils.get_base_cmd_bunwarpj( None ) -if cmd is None: - imagej2_base_utils.stop_err( "bUnwarpJ not found!" ) -cmd += ' -adapt_transform' - -# Make sure the value of image_size_factor is a power of 2 (positive or negative). -if is_power2( args.image_size_factor ): - image_size_factor = args.image_size_factor -else: - msg = "Image size factor must be a positive or negative power of 2 (0.25, 0.5, 2, 4, 8, etc)." - imagej2_base_utils.stop_err( msg ) - -# Target is sent before source. -cmd += ' %s' % target_image_path -cmd += ' %s' % source_image_path -cmd += ' %s' % input_elastic_transformation_path -cmd += ' %s' % args.output -cmd += ' %2.f' % image_size_factor - -# Adapt the transformation based on the image size factor using bUnwarpJ. -proc = subprocess.Popen( args=cmd, stderr=subprocess.PIPE, stdout=subprocess.PIPE, shell=True ) -rc = proc.wait() -if rc != 0: - error_message = imagej2_base_utils.get_stderr_exception( tmp_err, tmp_stderr, tmp_out, tmp_stdout ) - imagej2_base_utils.stop_err( error_message ) - -imagej2_base_utils.cleanup_before_exit( tmp_dir ) |
b |
diff -r a84f2cbf091b -r 4c43ba752312 imagej2_bunwarpj_align.py --- a/imagej2_bunwarpj_align.py Tue Sep 17 17:08:08 2019 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 |
b |
b"@@ -1,178 +0,0 @@\n-#!/usr/bin/env python\n-import argparse\n-import os\n-import shutil\n-import subprocess\n-import tempfile\n-import imagej2_base_utils\n-\n-# Parse Command Line.\n-parser = argparse.ArgumentParser()\n-parser.add_argument( '--source_image', dest='source_image', help='Source image' )\n-parser.add_argument( '--source_image_format', dest='source_image_format', help='Source image format' )\n-parser.add_argument( '--source_mask', dest='source_mask', default=None, help='Source mask' )\n-parser.add_argument( '--source_mask_format', dest='source_mask_format', default=None, help='Source mask image format' )\n-parser.add_argument( '--target_image', dest='target_image', help='Target image' )\n-parser.add_argument( '--target_image_format', dest='target_image_format', help='Target image format' )\n-parser.add_argument( '--target_mask', dest='target_mask', default=None, help='Target mask' )\n-parser.add_argument( '--target_mask_format', dest='target_mask_format', default=None, help='Target mask image format' )\n-parser.add_argument( '--min_scale_def', dest='min_scale_def', type=int, help='Initial deformation' )\n-parser.add_argument( '--max_scale_def', dest='max_scale_def', type=int, help='Final deformation' )\n-parser.add_argument( '--max_subsamp_fact', dest='max_subsamp_fact', type=int, help='Image sub-sample factor' )\n-parser.add_argument( '--divergence_weight', dest='divergence_weight', type=float, help='Divergence weight' )\n-parser.add_argument( '--curl_weight', dest='curl_weight', type=float, help='Curl weight' )\n-parser.add_argument( '--image_weight', dest='image_weight', type=float, help='Image weight' )\n-parser.add_argument( '--consistency_weight', dest='consistency_weight', type=float, help='Consistency weight' )\n-parser.add_argument( '--landmarks_weight', dest='landmarks_weight', type=float, help='Landmarks weight' )\n-parser.add_argument( '--landmarks_file', dest='landmarks_file', default=None, help='Landmarks file' )\n-parser.add_argument( '--source_affine_file', dest='source_affine_file', default=None, help='Initial source affine matrix transformation' )\n-parser.add_argument( '--target_affine_file', dest='target_affine_file', default=None, help='Initial target affine matrix transformation' )\n-parser.add_argument( '--mono', dest='mono', default=False, help='Unidirectional registration (source to target)' )\n-parser.add_argument( '--source_trans_out', dest='source_trans_out', default=None, help='Direct source transformation matrix' )\n-parser.add_argument( '--target_trans_out', dest='target_trans_out', default=None, help='Inverse target transformation matrix' )\n-parser.add_argument( '--source_out', help='Output source image' )\n-parser.add_argument( '--source_out_datatype', help='Output registered source image format' )\n-parser.add_argument( '--target_out', default=None, help='Output target image' )\n-parser.add_argument( '--target_out_datatype', default=None, help='Output registered target image format' )\n-parser.add_argument( '--jython_script', dest='jython_script', help='Path to the Jython script' )\n-\n-args = parser.parse_args()\n-\n-if args.source_trans_out is not None and args.target_trans_out is not None:\n- save_transformation = True\n-else:\n- save_transformation = False\n-\n-tmp_dir = imagej2_base_utils.get_temp_dir()\n-source_image_path = imagej2_base_utils.get_input_image_path( tmp_dir, args.source_image, args.source_image_format )\n-tmp_source_out_tiff_path = imagej2_base_utils.get_temporary_image_path( tmp_dir, 'tiff' )\n-tmp_source_out_path = imagej2_base_utils.get_temporary_image_path( tmp_dir, args.source_out_datatype )\n-target_image_path = imagej2_base_utils.get_input_image_path( tmp_dir, args.target_image, args.target_image_format )\n-if not args.mono:\n- tmp_target_out_tiff_path = imagej2_base_utils.get_temporary_image_path( tmp_dir, 'tiff' )\n- tmp_target_out_path = imagej2_base_utils.get_temporary_image_path( tmp_dir, args.target_out_datatype )\n-if args.source_mask is not None and args.target_mask is not None:\n- t"..b'max_scale_def\n-cmd += \' %d\' % args.max_subsamp_fact\n-cmd += \' %.1f\' % args.divergence_weight\n-cmd += \' %.1f\' % args.curl_weight\n-cmd += \' %.1f\' % args.image_weight\n-cmd += \' %.1f\' % args.consistency_weight\n-# Source is produced before target.\n-cmd += \' %s\' % tmp_source_out_tiff_path\n-if not args.mono:\n- cmd += \' %s\' % tmp_target_out_tiff_path\n-if args.landmarks_file is not None:\n- # We have to create a temporary file with a .txt extension here so that\n- # bUnwarpJ will not ignore the Galaxy "dataset.dat" file.\n- tmp_landmarks_file_path = imagej2_base_utils.get_input_image_path( tmp_dir,\n- args.landmarks_file,\n- \'txt\' )\n- cmd += \' -landmarks\'\n- cmd += \' %.1f\' % args.landmarks_weight\n- cmd += \' %s\' % tmp_landmarks_file_path\n-if args.source_affine_file is not None and args.target_affine_file is not None:\n- # Target is sent before source.\n- cmd += \' -affine\'\n- cmd += \' %s\' % args.target_affine_file\n- cmd += \' %s\' % args.source_affine_file\n-if args.mono:\n- cmd += \' -mono\'\n-if save_transformation:\n- cmd += \' -save_transformation\'\n-\n-# Align the two images using bUnwarpJ.\n-proc = subprocess.Popen( args=cmd, stderr=tmp_stderr, stdout=tmp_stdout, shell=True )\n-rc = proc.wait()\n-if rc != 0:\n- error_message = imagej2_base_utils.get_stderr_exception( tmp_err, tmp_stderr, tmp_out, tmp_stdout )\n- imagej2_base_utils.stop_err( error_message )\n-\n-# bUnwarpJ produces tiff image stacks consisting of 3 slices which can be viewed in ImageJ.\n-# The 3 slices are:: 1) the registered image, 2) the target image and 3) the black/white\n-# warp image. Galaxy supports only single-layered images, so we\'ll convert the images so they\n-# can be viewed in Galaxy.\n-\n-# Define command response buffers.\n-tmp_out = tempfile.NamedTemporaryFile().name\n-tmp_stdout = open( tmp_out, \'wb\' )\n-tmp_err = tempfile.NamedTemporaryFile().name\n-tmp_stderr = open( tmp_err, \'wb\' )\n-\n-# Build the command line to handle the multi-slice tiff images.\n-cmd = imagej2_base_utils.get_base_command_imagej2( None, jython_script=args.jython_script )\n-if cmd is None:\n- imagej2_base_utils.stop_err( "ImageJ not found!" )\n-if args.mono:\n- # bUnwarpJ will produce only a registered source image.\n- cmd += \' %s %s %s %s\' % ( tmp_source_out_tiff_path,\n- args.source_out_datatype,\n- tmp_source_out_path,\n- args.mono )\n-else:\n- # bUnwarpJ will produce registered source and target images.\n- cmd += \' %s %s %s %s %s %s %s\' % ( tmp_source_out_tiff_path,\n- args.source_out_datatype,\n- tmp_source_out_path,\n- tmp_target_out_tiff_path,\n- args.target_out_datatype,\n- tmp_target_out_path,\n- args.mono )\n-\n-# Merge the multi-slice tiff layers into an image that can be viewed in Galaxy.\n-proc = subprocess.Popen( args=cmd, stderr=tmp_stderr, stdout=tmp_stdout, shell=True )\n-rc = proc.wait()\n-if rc != 0:\n- error_message = imagej2_base_utils.get_stderr_exception( tmp_err, tmp_stderr, tmp_out, tmp_stdout )\n- imagej2_base_utils.stop_err( error_message )\n-\n-# Save the Registered Source Image to the output dataset.\n-shutil.move( tmp_source_out_path, args.source_out )\n-if not args.mono:\n- # Move the Registered Target Image to the output dataset.\n- shutil.move( tmp_target_out_path, args.target_out )\n-\n-# If requested, save matrix transformations as additional datasets.\n-if save_transformation:\n- shutil.move( tmp_source_out_transf_path, args.source_trans_out )\n- if not args.mono:\n- shutil.move( tmp_target_out_transf_path, args.target_trans_out )\n-\n-imagej2_base_utils.cleanup_before_exit( tmp_dir )\n' |
b |
diff -r a84f2cbf091b -r 4c43ba752312 imagej2_bunwarpj_align_jython_script.py --- a/imagej2_bunwarpj_align_jython_script.py Tue Sep 17 17:08:08 2019 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 |
[ |
@@ -1,37 +0,0 @@ -import sys -import jython_utils -from ij import IJ - -# Fiji Jython interpreter implements Python 2.5 which does not -# provide support for argparse. - -if sys.argv[ -1 ].lower() in [ 'true' ]: - mono = True -else: - mono = False - -if mono: - # bUnwarpJ has been called with the -mono param. - source_tiff_path = sys.argv[ -4 ] - source_datatype = sys.argv[ -3 ] - source_path = sys.argv[ -2 ] -else: - source_tiff_path = sys.argv[ -7 ] - source_datatype = sys.argv[ -6 ] - source_path = sys.argv[ -5 ] - target_tiff_path = sys.argv[ -4 ] - target_datatype = sys.argv[ -3 ] - target_path = sys.argv[ -2 ] - -# Save the Registered Source Image. -registered_source_image = IJ.openImage( source_tiff_path ) -if source_datatype == 'tiff': - registered_source_image = jython_utils.convert_before_saving_as_tiff( registered_source_image ) -IJ.saveAs( registered_source_image, source_datatype, source_path ) - -if not mono: - # Save the Registered Target Image. - registered_target_image = IJ.openImage( target_tiff_path ) - if target_datatype == 'tiff': - registered_target_image = jython_utils.convert_before_saving_as_tiff( registered_target_image ) - IJ.saveAs( registered_target_image, target_datatype, target_path ) |
b |
diff -r a84f2cbf091b -r 4c43ba752312 imagej2_bunwarpj_compare_elastic.py --- a/imagej2_bunwarpj_compare_elastic.py Tue Sep 17 17:08:08 2019 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 |
[ |
@@ -1,65 +0,0 @@ -#!/usr/bin/env python -import argparse -import subprocess -import tempfile -import imagej2_base_utils - -# Parse Command Line. -parser = argparse.ArgumentParser() -parser.add_argument( '--source_image', dest='source_image', help='Source image' ) -parser.add_argument( '--source_image_format', dest='source_image_format', help='Source image format' ) -parser.add_argument( '--target_image', dest='target_image', help='Target image' ) -parser.add_argument( '--target_image_format', dest='target_image_format', help='Target image format' ) -parser.add_argument( '--source_transformation', dest='source_transformation', help='Direct source transformation matrix' ) -parser.add_argument( '--target_transformation', dest='target_transformation', help='Inverse target transformation matrix' ) -parser.add_argument( '--output', dest='output', help='Warping index' ) - -args = parser.parse_args() - -tmp_dir = imagej2_base_utils.get_temp_dir() -source_image_path = imagej2_base_utils.get_input_image_path( tmp_dir, args.source_image, args.source_image_format ) -target_image_path = imagej2_base_utils.get_input_image_path( tmp_dir, args.target_image, args.target_image_format ) -source_transformation_path = imagej2_base_utils.get_input_image_path( tmp_dir, args.source_transformation, 'txt' ) -target_transformation_path = imagej2_base_utils.get_input_image_path( tmp_dir, args.target_transformation, 'txt' ) -# bUnwarpJ produces several lines of output that we need to discard, so -# we'll use a temporary output file from which we'll read only the last line. -tmp_output_path = imagej2_base_utils.get_input_image_path( tmp_dir, args.output, 'txt' ) - -# 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' ) - -# Build the command line to calculate the warping index. -cmd = imagej2_base_utils.get_base_cmd_bunwarpj( None ) -if cmd is None: - imagej2_base_utils.stop_err( "bUnwarpJ not found!" ) -cmd += ' -compare_elastic' -# Target is sent before source. -cmd += ' %s' % target_image_path -cmd += ' %s' % source_image_path -cmd += ' %s' % target_transformation_path -cmd += ' %s' % source_transformation_path -cmd += ' > %s' % tmp_output_path - -# Calculate the warping index of two elastic transformations using bUnwarpJ. -proc = subprocess.Popen( args=cmd, stderr=subprocess.PIPE, stdout=subprocess.PIPE, shell=True ) -rc = proc.wait() -if rc != 0: - error_message = imagej2_base_utils.get_stderr_exception( tmp_err, tmp_stderr, tmp_out, tmp_stdout ) - imagej2_base_utils.stop_err( error_message ) - -# Example contents of tmp_output_path: -# ['Target image : ~/tmpKAYF1P.jpg\n', -# 'Source image : ~/tmpgQX0dy.gif\n', -# 'Target Transformation file : ~/tmpZJC_4B.txt\n', -# 'Source Transformation file : ~/tmphsSojl.txt\n', -# ' Warping index = 14.87777347388348\n'] -results = open( tmp_output_path, 'r' ).readlines() -warp_index = results[ -1 ].split( ' ' )[ -1 ] -outf = open( args.output, 'wb' ) -outf.write( '%s' % warp_index ) -outf.close() - -imagej2_base_utils.cleanup_before_exit( tmp_dir ) |
b |
diff -r a84f2cbf091b -r 4c43ba752312 imagej2_bunwarpj_compare_elastic_raw.py --- a/imagej2_bunwarpj_compare_elastic_raw.py Tue Sep 17 17:08:08 2019 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 |
[ |
@@ -1,64 +0,0 @@ -#!/usr/bin/env python -import argparse -import subprocess -import tempfile -import imagej2_base_utils - -# Parse Command Line. -parser = argparse.ArgumentParser() -parser.add_argument( '--source_image', dest='source_image', help='Source image' ) -parser.add_argument( '--source_image_format', dest='source_image_format', help='Source image format' ) -parser.add_argument( '--target_image', dest='target_image', help='Target image' ) -parser.add_argument( '--target_image_format', dest='target_image_format', help='Target image format' ) -parser.add_argument( '--target_elastic_transformation', dest='target_elastic_transformation', help='Target elastic transformation matrix' ) -parser.add_argument( '--source_raw_transformation', dest='source_raw_transformation', help='Source raw transformation matrix' ) -parser.add_argument( '--output', dest='output', help='Warping index' ) - -args = parser.parse_args() - -tmp_dir = imagej2_base_utils.get_temp_dir() -source_image_path = imagej2_base_utils.get_input_image_path( tmp_dir, args.source_image, args.source_image_format ) -target_image_path = imagej2_base_utils.get_input_image_path( tmp_dir, args.target_image, args.target_image_format ) -target_elastic_transformation_path = imagej2_base_utils.get_input_image_path( tmp_dir, args.target_elastic_transformation, 'txt' ) -source_raw_transformation_path = imagej2_base_utils.get_input_image_path( tmp_dir, args.source_raw_transformation, 'txt' ) -# bUnwarpJ produces several lines of output that we need to discard, so -# we'll use a temporary output file from which we'll read only the last line. -tmp_output_path = imagej2_base_utils.get_input_image_path( tmp_dir, args.output, 'txt' ) - -# 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' ) - -# Build the command line to calculate the warping index. -cmd = imagej2_base_utils.get_base_cmd_bunwarpj( None ) -if cmd is None: - imagej2_base_utils.stop_err( "bUnwarpJ not found!" ) -cmd += ' -compare_elastic_raw' -cmd += ' %s' % target_image_path -cmd += ' %s' % source_image_path -cmd += ' %s' % target_elastic_transformation_path -cmd += ' %s' % source_raw_transformation_path -cmd += ' > %s' % tmp_output_path - -# Calculate the warping index of elastic and raw transformations using bUnwarpJ. -proc = subprocess.Popen( args=cmd, stderr=subprocess.PIPE, stdout=subprocess.PIPE, shell=True ) -rc = proc.wait() -if rc != 0: - error_message = imagej2_base_utils.get_stderr_exception( tmp_err, tmp_stderr, tmp_out, tmp_stdout ) - imagej2_base_utils.stop_err( error_message ) - -# Example contents of tmp_output_path: -# ['Target image : ~/tmpHdt9Cs.jpg\n', -# 'Source image : ~/tmpu6kyfc.gif\n', -# 'Elastic Transformation file : ~/tmp4vZurG.txt\n', -# 'Raw Transformation file : ~/tmp2PNQcT.txt\n', -# ' Warping index = 25.007467512204983\n'] -results = open( tmp_output_path, 'r' ).readlines() -warp_index = results[ -1 ].split( ' ' )[ -1 ] -outf = open( args.output, 'wb' ) -outf.write( '%s' % warp_index ) -outf.close() - -imagej2_base_utils.cleanup_before_exit( tmp_dir ) |
b |
diff -r a84f2cbf091b -r 4c43ba752312 imagej2_bunwarpj_compare_raw.py --- a/imagej2_bunwarpj_compare_raw.py Tue Sep 17 17:08:08 2019 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 |
[ |
@@ -1,64 +0,0 @@ -#!/usr/bin/env python -import argparse -import subprocess -import tempfile -import imagej2_base_utils - -# Parse Command Line. -parser = argparse.ArgumentParser() -parser.add_argument( '--source_image', dest='source_image', help='Source image' ) -parser.add_argument( '--source_image_format', dest='source_image_format', help='Source image format' ) -parser.add_argument( '--target_image', dest='target_image', help='Target image' ) -parser.add_argument( '--target_image_format', dest='target_image_format', help='Target image format' ) -parser.add_argument( '--target_raw_transformation', dest='target_raw_transformation', help='First raw transformation matrix' ) -parser.add_argument( '--source_raw_transformation', dest='source_raw_transformation', help='Second raw transformation matrix' ) -parser.add_argument( '--output', dest='output', help='Warping index' ) - -args = parser.parse_args() - -tmp_dir = imagej2_base_utils.get_temp_dir() -source_image_path = imagej2_base_utils.get_input_image_path( tmp_dir, args.source_image, args.source_image_format ) -target_image_path = imagej2_base_utils.get_input_image_path( tmp_dir, args.target_image, args.target_image_format ) -target_raw_transformation_path = imagej2_base_utils.get_input_image_path( tmp_dir, args.target_raw_transformation, 'txt' ) -source_raw_transformation_path = imagej2_base_utils.get_input_image_path( tmp_dir, args.source_raw_transformation, 'txt' ) -# bUnwarpJ produces several lines of output that we need to discard, so -# we'll use a temporary output file from which we'll read only the last line. -tmp_output_path = imagej2_base_utils.get_input_image_path( tmp_dir, args.output, 'txt' ) - -# 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' ) - -# Build the command line to calculate the warping index. -cmd = imagej2_base_utils.get_base_cmd_bunwarpj( None ) -if cmd is None: - imagej2_base_utils.stop_err( "bUnwarpJ not found!" ) -cmd += ' -compare_raw' -cmd += ' %s' % target_image_path -cmd += ' %s' % source_image_path -cmd += ' %s' % target_raw_transformation_path -cmd += ' %s' % source_raw_transformation_path -cmd += ' > %s' % tmp_output_path - -# Calculate the warping index of two raw transformations using bUnwarpJ. -proc = subprocess.Popen( args=cmd, stderr=subprocess.PIPE, stdout=subprocess.PIPE, shell=True ) -rc = proc.wait() -if rc != 0: - error_message = imagej2_base_utils.get_stderr_exception( tmp_err, tmp_stderr, tmp_out, tmp_stdout ) - imagej2_base_utils.stop_err( error_message ) - -# Example contents of tmp_output_path: -# ['Target image : ~/tmp5WmDku.jpg\n', -# 'Source image : ~/tmps74U40.gif\n', -# 'Target Transformation file : ~/tmpXofC1x.txt\n', -# 'Source Transformation file : ~/tmpFqNYe4.txt\n', -# ' Warping index = 24.111209027033937\n'] -results = open( tmp_output_path, 'r' ).readlines() -warp_index = results[ -1 ].split( ' ' )[ -1 ] -outf = open( args.output, 'wb' ) -outf.write( '%s' % warp_index ) -outf.close() - -imagej2_base_utils.cleanup_before_exit( tmp_dir ) |
b |
diff -r a84f2cbf091b -r 4c43ba752312 imagej2_bunwarpj_compose_elastic.py --- a/imagej2_bunwarpj_compose_elastic.py Tue Sep 17 17:08:08 2019 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 |
b |
@@ -1,50 +0,0 @@ -#!/usr/bin/env python -import argparse -import subprocess -import tempfile -import imagej2_base_utils - -# Parse Command Line. -parser = argparse.ArgumentParser() -parser.add_argument( '--source_image', dest='source_image', help='Source image' ) -parser.add_argument( '--source_image_format', dest='source_image_format', help='Source image format' ) -parser.add_argument( '--target_image', dest='target_image', help='Target image' ) -parser.add_argument( '--target_image_format', dest='target_image_format', help='Target image format' ) -parser.add_argument( '--source_elastic_transformation', dest='source_elastic_transformation', help='Direct source transformation matrix' ) -parser.add_argument( '--target_elastic_transformation', dest='target_elastic_transformation', help='Inverse target transformation matrix' ) -parser.add_argument( '--output', dest='output', help='Warping index' ) - -args = parser.parse_args() - -tmp_dir = imagej2_base_utils.get_temp_dir() -source_image_path = imagej2_base_utils.get_input_image_path( tmp_dir, args.source_image, args.source_image_format ) -target_image_path = imagej2_base_utils.get_input_image_path( tmp_dir, args.target_image, args.target_image_format ) -source_elastic_transformation_path = imagej2_base_utils.get_input_image_path( tmp_dir, args.source_elastic_transformation, 'txt' ) -target_elastic_transformation_path = imagej2_base_utils.get_input_image_path( tmp_dir, args.target_elastic_transformation, 'txt' ) - -# 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' ) - -# Build the command line to compose the transformations. -cmd = imagej2_base_utils.get_base_cmd_bunwarpj( None ) -if cmd is None: - imagej2_base_utils.stop_err( "bUnwarpJ not found!" ) -cmd += ' -compose_elastic' -# Target is sent before source. -cmd += ' %s' % target_image_path -cmd += ' %s' % source_image_path -cmd += ' %s' % target_elastic_transformation_path -cmd += ' %s' % source_elastic_transformation_path -cmd += ' %s' % args.output - -# Compose the two elastic transformations into a raw transformation using bUnwarpJ. -proc = subprocess.Popen( args=cmd, stderr=subprocess.PIPE, stdout=subprocess.PIPE, shell=True ) -rc = proc.wait() -if rc != 0: - error_message = imagej2_base_utils.get_stderr_exception( tmp_err, tmp_stderr, tmp_out, tmp_stdout ) - imagej2_base_utils.stop_err( error_message ) - -imagej2_base_utils.cleanup_before_exit( tmp_dir ) |
b |
diff -r a84f2cbf091b -r 4c43ba752312 imagej2_bunwarpj_compose_raw.py --- a/imagej2_bunwarpj_compose_raw.py Tue Sep 17 17:08:08 2019 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 |
b |
@@ -1,50 +0,0 @@ -#!/usr/bin/env python -import argparse -import subprocess -import tempfile -import imagej2_base_utils - -# Parse Command Line. -parser = argparse.ArgumentParser() -parser.add_argument( '--source_image', dest='source_image', help='Source image' ) -parser.add_argument( '--source_image_format', dest='source_image_format', help='Source image format' ) -parser.add_argument( '--target_image', dest='target_image', help='Target image' ) -parser.add_argument( '--target_image_format', dest='target_image_format', help='Target image format' ) -parser.add_argument( '--source_raw_transformation', dest='source_raw_transformation', help='Direct source transformation matrix' ) -parser.add_argument( '--target_raw_transformation', dest='target_raw_transformation', help='Inverse target transformation matrix' ) -parser.add_argument( '--output', dest='output', help='Warping index' ) - -args = parser.parse_args() - -tmp_dir = imagej2_base_utils.get_temp_dir() -source_image_path = imagej2_base_utils.get_input_image_path( tmp_dir, args.source_image, args.source_image_format ) -target_image_path = imagej2_base_utils.get_input_image_path( tmp_dir, args.target_image, args.target_image_format ) -source_raw_transformation_path = imagej2_base_utils.get_input_image_path( tmp_dir, args.source_raw_transformation, 'txt' ) -target_raw_transformation_path = imagej2_base_utils.get_input_image_path( tmp_dir, args.target_raw_transformation, 'txt' ) - -# 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' ) - -# Build the command line to compose the two raw transformations. -cmd = imagej2_base_utils.get_base_cmd_bunwarpj( None ) -if cmd is None: - imagej2_base_utils.stop_err( "bUnwarpJ not found!" ) -cmd += ' -compose_raw' -# Target is sent before source. -cmd += ' %s' % target_image_path -cmd += ' %s' % source_image_path -cmd += ' %s' % target_raw_transformation_path -cmd += ' %s' % source_raw_transformation_path -cmd += ' %s' % args.output - -# Compose the two raw transformations into another raw transformation using bUnwarpJ. -proc = subprocess.Popen( args=cmd, stderr=subprocess.PIPE, stdout=subprocess.PIPE, shell=True ) -rc = proc.wait() -if rc != 0: - error_message = imagej2_base_utils.get_stderr_exception( tmp_err, tmp_stderr, tmp_out, tmp_stdout ) - imagej2_base_utils.stop_err( error_message ) - -imagej2_base_utils.cleanup_before_exit( tmp_dir ) |
b |
diff -r a84f2cbf091b -r 4c43ba752312 imagej2_bunwarpj_compose_raw_elastic.py --- a/imagej2_bunwarpj_compose_raw_elastic.py Tue Sep 17 17:08:08 2019 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 |
b |
@@ -1,50 +0,0 @@ -#!/usr/bin/env python -import argparse -import subprocess -import tempfile -import imagej2_base_utils - -# Parse Command Line. -parser = argparse.ArgumentParser() -parser.add_argument( '--source_image', dest='source_image', help='Source image' ) -parser.add_argument( '--source_image_format', dest='source_image_format', help='Source image format' ) -parser.add_argument( '--target_image', dest='target_image', help='Target image' ) -parser.add_argument( '--target_image_format', dest='target_image_format', help='Target image format' ) -parser.add_argument( '--source_elastic_transformation', dest='source_elastic_transformation', help='Direct source transformation matrix' ) -parser.add_argument( '--target_raw_transformation', dest='target_raw_transformation', help='Inverse target transformation matrix' ) -parser.add_argument( '--output', dest='output', help='Warping index' ) - -args = parser.parse_args() - -tmp_dir = imagej2_base_utils.get_temp_dir() -source_image_path = imagej2_base_utils.get_input_image_path( tmp_dir, args.source_image, args.source_image_format ) -target_image_path = imagej2_base_utils.get_input_image_path( tmp_dir, args.target_image, args.target_image_format ) -source_elastic_transformation_path = imagej2_base_utils.get_input_image_path( tmp_dir, args.source_elastic_transformation, 'txt' ) -target_raw_transformation_path = imagej2_base_utils.get_input_image_path( tmp_dir, args.target_raw_transformation, 'txt' ) - -# 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' ) - -# Build the command line to compose the raw and elastic transformations. -cmd = imagej2_base_utils.get_base_cmd_bunwarpj( None ) -if cmd is None: - imagej2_base_utils.stop_err( "bUnwarpJ not found!" ) -cmd += ' -compose_raw_elastic' -# Target is sent before source. -cmd += ' %s' % target_image_path -cmd += ' %s' % source_image_path -cmd += ' %s' % target_raw_transformation_path -cmd += ' %s' % source_elastic_transformation_path -cmd += ' %s' % args.output - -# Compose the raw and elastic transformations into another raw transformation using bUnwarpJ. -proc = subprocess.Popen( args=cmd, stderr=subprocess.PIPE, stdout=subprocess.PIPE, shell=True ) -rc = proc.wait() -if rc != 0: - error_message = imagej2_base_utils.get_stderr_exception( tmp_err, tmp_stderr, tmp_out, tmp_stdout ) - imagej2_base_utils.stop_err( error_message ) - -imagej2_base_utils.cleanup_before_exit( tmp_dir ) |
b |
diff -r a84f2cbf091b -r 4c43ba752312 imagej2_bunwarpj_convert_to_raw.py --- a/imagej2_bunwarpj_convert_to_raw.py Tue Sep 17 17:08:08 2019 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 |
b |
@@ -1,47 +0,0 @@ -#!/usr/bin/env python -import argparse -import subprocess -import tempfile -import imagej2_base_utils - -# Parse Command Line. -parser = argparse.ArgumentParser() -parser.add_argument( '--source_image', dest='source_image', help='Source image' ) -parser.add_argument( '--source_image_format', dest='source_image_format', help='Source image format' ) -parser.add_argument( '--target_image', dest='target_image', help='Target image' ) -parser.add_argument( '--target_image_format', dest='target_image_format', help='Target image format' ) -parser.add_argument( '--elastic_transformation', dest='elastic_transformation', help='Elastic transformation as saved by bUnwarpJ in elastic format' ) -parser.add_argument( '--raw_transformation', dest='raw_transformation', help='Raw transformation' ) - -args = parser.parse_args() - -tmp_dir = imagej2_base_utils.get_temp_dir() -source_image_path = imagej2_base_utils.get_input_image_path( tmp_dir, args.source_image, args.source_image_format ) -target_image_path = imagej2_base_utils.get_input_image_path( tmp_dir, args.target_image, args.target_image_format ) -elastic_transformation_path = imagej2_base_utils.get_input_image_path( tmp_dir, args.elastic_transformation, 'txt' ) - -# 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' ) - -# Build the command line to convert the B-spline (i.e., elastic) transformation to raw. -cmd = imagej2_base_utils.get_base_cmd_bunwarpj( None ) -if cmd is None: - imagej2_base_utils.stop_err( "bUnwarpJ not found!" ) -cmd += ' -convert_to_raw' -# Target is sent before source. -cmd += ' %s' % target_image_path -cmd += ' %s' % source_image_path -cmd += ' %s' % elastic_transformation_path -cmd += ' %s' % args.raw_transformation - -# Convert the elastic transformation to raw using bUnwarpJ. -proc = subprocess.Popen( args=cmd, stderr=tmp_stderr, stdout=tmp_stdout, shell=True ) -rc = proc.wait() -if rc != 0: - error_message = imagej2_base_utils.get_stderr_exception( tmp_err, tmp_stderr, tmp_out, tmp_stdout ) - imagej2_base_utils.stop_err( error_message ) - -imagej2_base_utils.cleanup_before_exit( tmp_dir ) |
b |
diff -r a84f2cbf091b -r 4c43ba752312 imagej2_bunwarpj_elastic_transform.py --- a/imagej2_bunwarpj_elastic_transform.py Tue Sep 17 17:08:08 2019 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 |
b |
@@ -1,73 +0,0 @@ -#!/usr/bin/env python -import argparse -import shutil -import subprocess -import tempfile -import imagej2_base_utils - -# Parse Command Line. -parser = argparse.ArgumentParser() -parser.add_argument( '--source_image', dest='source_image', help='Source image' ) -parser.add_argument( '--source_image_format', dest='source_image_format', help='Source image format' ) -parser.add_argument( '--target_image', dest='target_image', help='Target image' ) -parser.add_argument( '--target_image_format', dest='target_image_format', help='Target image format' ) -parser.add_argument( '--elastic_transformation', dest='elastic_transformation', help='Elastic transformation as saved by bUnwarpJ in elastic format' ) -parser.add_argument( '--source_out', help='Output source image' ) -parser.add_argument( '--source_out_datatype', help='Output registered source image format' ) -parser.add_argument( '--jython_script', dest='jython_script', help='Path to the Jython script' ) - -args = parser.parse_args() - -tmp_dir = imagej2_base_utils.get_temp_dir() -source_image_path = imagej2_base_utils.get_input_image_path( tmp_dir, args.source_image, args.source_image_format ) -tmp_source_out_tiff_path = imagej2_base_utils.get_temporary_image_path( tmp_dir, 'tiff' ) -tmp_source_out_path = imagej2_base_utils.get_temporary_image_path( tmp_dir, args.source_out_datatype ) -target_image_path = imagej2_base_utils.get_input_image_path( tmp_dir, args.target_image, args.target_image_format ) -elastic_transformation_path = imagej2_base_utils.get_input_image_path( tmp_dir, args.elastic_transformation, 'txt' ) - -# 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' ) - -# Build the command line to apply the transformation. -cmd = imagej2_base_utils.get_base_cmd_bunwarpj( None ) -if cmd is None: - imagej2_base_utils.stop_err( "bUnwarpJ not found!" ) -cmd += ' -elastic_transform' -# Target is sent before source. -cmd += ' %s' % target_image_path -cmd += ' %s' % source_image_path -cmd += ' %s' % elastic_transformation_path -cmd += ' %s' % tmp_source_out_tiff_path - -# Apply the elastic transformation using bUnwarpJ. -proc = subprocess.Popen( args=cmd, stderr=tmp_stderr, stdout=tmp_stdout, shell=True ) -rc = proc.wait() -if rc != 0: - error_message = imagej2_base_utils.get_stderr_exception( tmp_err, tmp_stderr, tmp_out, tmp_stdout ) - imagej2_base_utils.stop_err( error_message ) - -# Convert the registered image to the specified output format. -tmp_out = tempfile.NamedTemporaryFile().name -tmp_stdout = open( tmp_out, 'wb' ) -tmp_err = tempfile.NamedTemporaryFile().name -tmp_stderr = open( tmp_err, 'wb' ) - -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 %s %s' % ( tmp_source_out_tiff_path, - args.source_out_datatype, - tmp_source_out_path ) - -proc = subprocess.Popen( args=cmd, stderr=tmp_stderr, stdout=tmp_stdout, shell=True ) -rc = proc.wait() -if rc != 0: - error_message = imagej2_base_utils.get_stderr_exception( tmp_err, tmp_stderr, tmp_out, tmp_stdout ) - imagej2_base_utils.stop_err( error_message ) - -# Save the Registered Source Image to the defined output. -shutil.move( tmp_source_out_path, args.source_out ) -imagej2_base_utils.cleanup_before_exit( tmp_dir ) |
b |
diff -r a84f2cbf091b -r 4c43ba752312 imagej2_bunwarpj_elastic_transform_jython_script.py --- a/imagej2_bunwarpj_elastic_transform_jython_script.py Tue Sep 17 17:08:08 2019 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 |
[ |
@@ -1,16 +0,0 @@ -import sys -import jython_utils -from ij import IJ - -# Fiji Jython interpreter implements Python 2.5 which does not -# provide support for argparse. - -source_tiff_path = sys.argv[ -3 ] -source_datatype = sys.argv[ -2 ] -source_path = sys.argv[ -1 ] - -# Save the Registered Source Image. -registered_source_image = IJ.openImage( source_tiff_path ) -if source_datatype == 'tiff': - registered_source_image = jython_utils.convert_before_saving_as_tiff( registered_source_image ) -IJ.saveAs( registered_source_image, source_datatype, source_path ) |
b |
diff -r a84f2cbf091b -r 4c43ba752312 imagej2_bunwarpj_raw_transform.py --- a/imagej2_bunwarpj_raw_transform.py Tue Sep 17 17:08:08 2019 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 |
b |
@@ -1,73 +0,0 @@ -#!/usr/bin/env python -import argparse -import shutil -import subprocess -import tempfile -import imagej2_base_utils - -# Parse Command Line. -parser = argparse.ArgumentParser() -parser.add_argument( '--source_image', dest='source_image', help='Source image' ) -parser.add_argument( '--source_image_format', dest='source_image_format', help='Source image format' ) -parser.add_argument( '--target_image', dest='target_image', help='Target image' ) -parser.add_argument( '--target_image_format', dest='target_image_format', help='Target image format' ) -parser.add_argument( '--raw_transformation', dest='raw_transformation', help='Raw transformation as saved by bUnwarpJ' ) -parser.add_argument( '--source_out', help='Output source image' ) -parser.add_argument( '--source_out_datatype', help='Output registered source image format' ) -parser.add_argument( '--jython_script', dest='jython_script', help='Path to the Jython script' ) - -args = parser.parse_args() - -tmp_dir = imagej2_base_utils.get_temp_dir() -source_image_path = imagej2_base_utils.get_input_image_path( tmp_dir, args.source_image, args.source_image_format ) -tmp_source_out_tiff_path = imagej2_base_utils.get_temporary_image_path( tmp_dir, 'tiff' ) -tmp_source_out_path = imagej2_base_utils.get_temporary_image_path( tmp_dir, args.source_out_datatype ) -target_image_path = imagej2_base_utils.get_input_image_path( tmp_dir, args.target_image, args.target_image_format ) -raw_transformation_path = imagej2_base_utils.get_input_image_path( tmp_dir, args.raw_transformation, 'txt' ) - -# 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' ) - -# Build the command line to apply the raw transformation. -cmd = imagej2_base_utils.get_base_cmd_bunwarpj( None ) -if cmd is None: - imagej2_base_utils.stop_err( "bUnwarpJ not found!" ) -cmd += ' -raw_transform' -# Target is sent before source. -cmd += ' %s' % target_image_path -cmd += ' %s' % source_image_path -cmd += ' %s' % raw_transformation_path -cmd += ' %s' % tmp_source_out_tiff_path - -# Apply the raw transformation using bUnwarpJ. -proc = subprocess.Popen( args=cmd, stderr=tmp_stderr, stdout=tmp_stdout, shell=True ) -rc = proc.wait() -if rc != 0: - error_message = imagej2_base_utils.get_stderr_exception( tmp_err, tmp_stderr, tmp_out, tmp_stdout ) - imagej2_base_utils.stop_err( error_message ) - -# Convert the registered image to the specified output format. -tmp_out = tempfile.NamedTemporaryFile().name -tmp_stdout = open( tmp_out, 'wb' ) -tmp_err = tempfile.NamedTemporaryFile().name -tmp_stderr = open( tmp_err, 'wb' ) - -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 %s %s' % ( tmp_source_out_tiff_path, - args.source_out_datatype, - tmp_source_out_path ) - -proc = subprocess.Popen( args=cmd, stderr=tmp_stderr, stdout=tmp_stdout, shell=True ) -rc = proc.wait() -if rc != 0: - error_message = imagej2_base_utils.get_stderr_exception( tmp_err, tmp_stderr, tmp_out, tmp_stdout ) - imagej2_base_utils.stop_err( error_message ) - -# Save the Registered Source Image to the defined output. -shutil.move( tmp_source_out_path, args.source_out ) -imagej2_base_utils.cleanup_before_exit( tmp_dir ) |
b |
diff -r a84f2cbf091b -r 4c43ba752312 imagej2_bunwarpj_raw_transform_jython_script.py --- a/imagej2_bunwarpj_raw_transform_jython_script.py Tue Sep 17 17:08:08 2019 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 |
[ |
@@ -1,16 +0,0 @@ -import sys -import jython_utils -from ij import IJ - -# Fiji Jython interpreter implements Python 2.5 which does not -# provide support for argparse. - -source_tiff_path = sys.argv[ -3 ] -source_datatype = sys.argv[ -2 ] -source_path = sys.argv[ -1 ] - -# Save the Registered Source Image. -registered_source_image = IJ.openImage( source_tiff_path ) -if source_datatype == 'tiff': - registered_source_image = jython_utils.convert_before_saving_as_tiff( registered_source_image ) -IJ.saveAs( registered_source_image, source_datatype, source_path ) |
b |
diff -r a84f2cbf091b -r 4c43ba752312 imagej2_create_image.py --- a/imagej2_create_image.py Tue Sep 17 17:08:08 2019 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 |
b |
@@ -1,40 +0,0 @@ -#!/usr/bin/env python -import argparse -import shutil -import subprocess -import tempfile -import imagej2_base_utils - -if __name__=="__main__": - # Parse Command Line. - parser = argparse.ArgumentParser() - parser.add_argument( '--width', dest='width', type=int, help='Image width in pixels' ) - parser.add_argument( '--height', dest='height', type=int, help='Image height in pixels' ) - parser.add_argument( '--depth', dest='depth', type=int, help='Image depth (specifies the number of stack slices)' ) - parser.add_argument( '--image_type', dest='image_type', help='Image type' ) - parser.add_argument( '--image_title', dest='image_title', default='', help='Image title' ) - parser.add_argument( '--output_datatype', dest='output_datatype', help='Output image format' ) - parser.add_argument( '--jython_script', dest='jython_script', help='Path to the Jython script' ) - parser.add_argument( '--out_fname', help='Path to the output file' ) - args = parser.parse_args() - - tmp_dir = imagej2_base_utils.get_temp_dir() - tmp_image_path = imagej2_base_utils.get_temporary_image_path( tmp_dir, args.output_datatype ) - - # 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' ) - # Build the command line. - 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 %d %d %d %s %s' % ( args.image_title, args.width, args.height, args.depth, args.image_type, tmp_image_path ) - proc = subprocess.Popen( args=cmd, stderr=tmp_stderr, stdout=tmp_stdout, shell=True ) - rc = proc.wait() - if rc != 0: - error_message = imagej2_base_utils.get_stderr_exception( tmp_err, tmp_stderr, tmp_out, tmp_stdout ) - imagej2_base_utils.stop_err( error_message ) - shutil.move( tmp_image_path, args.out_fname ) - imagej2_base_utils.cleanup_before_exit( tmp_dir ) |
b |
diff -r a84f2cbf091b -r 4c43ba752312 imagej2_create_image_jython_script.py --- a/imagej2_create_image_jython_script.py Tue Sep 17 17:08:08 2019 -0400 +++ b/imagej2_create_image_jython_script.py Mon Sep 28 16:38:24 2020 +0000 |
[ |
@@ -1,14 +1,15 @@ import sys + from ij import IJ # Fiji Jython interpreter implements Python 2.5 which does not # provide support for argparse. -title = sys.argv[ -6 ] -width = int( sys.argv[ -5 ] ) -height = int( sys.argv[ -4 ] ) -depth = int( sys.argv[ -3 ] ) -type = sys.argv[ -2 ].replace( '_', ' ' ) -tmp_image_path = sys.argv[ -1 ] +title = sys.argv[-6] +width = int(sys.argv[-5]) +height = int(sys.argv[-4]) +depth = int(sys.argv[-3]) +type = sys.argv[-2].replace('_', ' ') +tmp_image_path = sys.argv[-1] -imp = IJ.newImage( title, type, width, height, depth ) -IJ.save( imp, "%s" % tmp_image_path ) +imp = IJ.newImage(title, type, width, height, depth) +IJ.save(imp, "%s" % tmp_image_path) |
b |
diff -r a84f2cbf091b -r 4c43ba752312 imagej2_enhance_contrast.py --- a/imagej2_enhance_contrast.py Tue Sep 17 17:08:08 2019 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 |
b |
@@ -1,63 +0,0 @@ -#!/usr/bin/env python -import argparse -import os -import shutil -import subprocess -import tempfile -import imagej2_base_utils - -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( '--equalize_histogram', dest='equalize_histogram', help='Equalize_histogram' ) -parser.add_argument( '--saturated_pixels', dest='saturated_pixels', type=float, default=None, help='Saturated pixel pct' ) -parser.add_argument( '--normalize', dest='normalize', help='Normalize' ) -parser.add_argument( '--jython_script', dest='jython_script', help='Path to the Jython script' ) -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() - -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.output_datatype ) - -# 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( None, 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.equalize_histogram -cmd += imagej2_base_utils.handle_none_type( args.saturated_pixels ) -cmd += ' %s' % args.normalize -cmd += ' %s' % tmp_output_path -cmd += ' %s' % args.output_datatype - -# Run the command. -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_out, 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 ) |
b |
diff -r a84f2cbf091b -r 4c43ba752312 imagej2_enhance_contrast_jython_script.py --- a/imagej2_enhance_contrast_jython_script.py Tue Sep 17 17:08:08 2019 -0400 +++ b/imagej2_enhance_contrast_jython_script.py Mon Sep 28 16:38:24 2020 +0000 |
[ |
@@ -1,19 +1,19 @@ -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[ -7 ] -input = sys.argv[ -6 ] -equalize_histogram = jython_utils.asbool( sys.argv[ -5 ] ) -saturated_pixels = sys.argv[ -4 ] -normalize = jython_utils.asbool( sys.argv[ -3 ] ) -tmp_output_path = sys.argv[ -2 ] -output_datatype = sys.argv[ -1 ] +error_log = sys.argv[-7] +input = sys.argv[-6] +equalize_histogram = sys.argv[-5] == "yes" +saturated_pixels = sys.argv[-4] +normalize = sys.argv[-3] == "yes" +tmp_output_path = sys.argv[-2] +output_datatype = sys.argv[-1] # Open the input image file. -input_image_plus = IJ.openImage( input ) +input_image_plus = IJ.openImage(input) # Create a copy of the image. input_image_plus_copy = input_image_plus.duplicate() @@ -24,19 +24,16 @@ options = [] # If equalize_histogram, saturated_pixels and normalize are ignored. if equalize_histogram: - options.append( 'equalize' ) + options.append('equalize') else: - if saturated_pixels not in [ None, 'None' ]: + if saturated_pixels not in [None, 'None']: # Fiji allows only a single decimal place for this value. - options.append( 'saturated=%.3f' % float( saturated_pixels ) ) + options.append('saturated=%.3f' % float(saturated_pixels)) # Normalization of RGB images is not supported. if bit_depth != 24 and normalize: - options.append( 'normalize' ) -try: - # Run the command. - options = "%s" % ' '.join( options ) - IJ.run( input_image_plus_copy, "Enhance Contrast...", options ) - # 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 ) ) + options.append('normalize') +# Run the command. +options = "%s" % ' '.join(options) +IJ.run(input_image_plus_copy, "Enhance Contrast...", options) +# Save the ImagePlus object as a new image. +IJ.saveAs(input_image_plus_copy, output_datatype, tmp_output_path) |
b |
diff -r a84f2cbf091b -r 4c43ba752312 imagej2_find_edges.py --- a/imagej2_find_edges.py Tue Sep 17 17:08:08 2019 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 |
b |
@@ -1,57 +0,0 @@ -#!/usr/bin/env python -import argparse -import os -import shutil -import subprocess -import tempfile -import imagej2_base_utils - -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( '--jython_script', dest='jython_script', help='Path to the Jython script' ) -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() - -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.output_datatype ) - -# 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( None, 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' % tmp_output_path -cmd += ' %s' % args.output_datatype - -# Run the command. -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_out, 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 ) |
b |
diff -r a84f2cbf091b -r 4c43ba752312 imagej2_find_edges_jython_script.py --- a/imagej2_find_edges_jython_script.py Tue Sep 17 17:08:08 2019 -0400 +++ b/imagej2_find_edges_jython_script.py Mon Sep 28 16:38:24 2020 +0000 |
[ |
@@ -1,25 +1,22 @@ -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[ -4 ] -input = sys.argv[ -3 ] -tmp_output_path = sys.argv[ -2 ] -output_datatype = sys.argv[ -1 ] +error_log = sys.argv[-4] +input = 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 ) +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, "Find Edges", "" ) - # 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 ) ) +# Run the command. +IJ.run(input_image_plus_copy, "Find Edges", "") +# Save the ImagePlus object as a new image. +IJ.saveAs(input_image_plus_copy, output_datatype, tmp_output_path) |
b |
diff -r a84f2cbf091b -r 4c43ba752312 imagej2_find_maxima.py --- a/imagej2_find_maxima.py Tue Sep 17 17:08:08 2019 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 |
b |
@@ -1,69 +0,0 @@ -#!/usr/bin/env python -import argparse -import os -import shutil -import subprocess -import tempfile -import imagej2_base_utils - -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( '--scale_when_converting', dest='scale_when_converting', help='Scale when converting RGB image' ) -parser.add_argument( '--weighted_rgb_conversions', dest='weighted_rgb_conversions', help='Weighted RGB conversions for RGB image' ) -parser.add_argument( '--noise_tolerance', dest='noise_tolerance', type=int, help='Noise tolerance' ) -parser.add_argument( '--output_type', dest='output_type', help='Output type' ) -parser.add_argument( '--exclude_edge_maxima', dest='exclude_edge_maxima', help='Exclude edge maxima' ) -parser.add_argument( '--light_background', dest='light_background', help='Light background' ) -parser.add_argument( '--jython_script', dest='jython_script', help='Path to the Jython script' ) -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() - -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.output_datatype ) - -# 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( None, 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.scale_when_converting -cmd += ' %s' % args.weighted_rgb_conversions -cmd += ' %d' % args.noise_tolerance -cmd += ' %s' % args.output_type -cmd += ' %s' % args.exclude_edge_maxima -cmd += ' %s' % args.light_background -cmd += ' %s' % tmp_output_path -cmd += ' %s' % args.output_datatype - -# Run the command. -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_out, 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 ) |
b |
diff -r a84f2cbf091b -r 4c43ba752312 imagej2_find_maxima_jython_script.py --- a/imagej2_find_maxima_jython_script.py Tue Sep 17 17:08:08 2019 -0400 +++ b/imagej2_find_maxima_jython_script.py Mon Sep 28 16:38:24 2020 +0000 |
[ |
@@ -1,94 +1,90 @@ import sys -import jython_utils -from ij import ImagePlus, IJ + +from ij import IJ, ImagePlus from ij.plugin.filter import Analyzer, MaximumFinder from ij.process import ImageProcessor -from jarray import array # Fiji Jython interpreter implements Python 2.5 which does not # provide support for argparse. -error_log = sys.argv[ -10 ] -input = sys.argv[ -9 ] -scale_when_converting = jython_utils.asbool( sys.argv[ -8 ] ) -weighted_rgb_conversions = jython_utils.asbool( sys.argv[ -7 ] ) -noise_tolerance = int( sys.argv[ -6 ] ) -output_type = sys.argv[ -5 ] -exclude_edge_maxima = jython_utils.asbool( sys.argv[ -4 ] ) -light_background = jython_utils.asbool( sys.argv[ -3 ] ) -tmp_output_path = sys.argv[ -2 ] -output_datatype = sys.argv[ -1 ] +error_log = sys.argv[-10] +input_file = sys.argv[-9] +scale_when_converting = sys.argv[-8] == 'yes' +weighted_rgb_conversions = sys.argv[-7] == 'yes' +noise_tolerance = int(sys.argv[-6]) +output_type = sys.argv[-5] +exclude_edge_maxima = sys.argv[-4] == 'yes' +light_background = 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 ) +input_image_plus = IJ.openImage(input_file) # Create a copy of the image. input_image_plus_copy = input_image_plus.duplicate() image_processor_copy = input_image_plus_copy.getProcessor() bit_depth = image_processor_copy.getBitDepth() -analyzer = Analyzer( input_image_plus_copy ) +analyzer = Analyzer(input_image_plus_copy) -try: - # Set the conversion options. - options = [] - # The following 2 options are applicable only to RGB images. - if bit_depth == 24: - if scale_when_converting: - option.append( "scale" ) - if weighted_rgb_conversions: - options.append( "weighted" ) - # Perform conversion - must happen even if no options are set. - IJ.run( input_image_plus_copy, "Conversions...", "%s" % " ".join( options ) ) - if output_type in [ 'List', 'Count' ]: - # W're generating a tabular file for the output. - # Set the Find Maxima options. - options = [ 'noise=%d' % noise_tolerance ] - if output_type.find( '_' ) > 0: - output_type_str = 'output=[%s]' % output_type.replace( '_', ' ' ) - else: - output_type_str = 'output=%s' % output_type - options.append( output_type_str ) - if exclude_edge_maxima: - options.append( 'exclude' ) - if light_background: - options.append( 'light' ) - # Run the command. - IJ.run( input_image_plus_copy, "Find Maxima...", "%s" % " ".join( options ) ) - results_table = analyzer.getResultsTable() - results_table.saveAs( tmp_output_path ) +# Set the conversion options. +options = [] +# The following 2 options are applicable only to RGB images. +if bit_depth == 24: + if scale_when_converting: + options.append("scale") + if weighted_rgb_conversions: + options.append("weighted") +# Perform conversion - must happen even if no options are set. +IJ.run(input_image_plus_copy, "Conversions...", "%s" % " ".join(options)) +if output_type in ['List', 'Count']: + # W're generating a tabular file for the output. + # Set the Find Maxima options. + options = ['noise=%d' % noise_tolerance] + if output_type.find('_') > 0: + output_type_str = 'output=[%s]' % output_type.replace('_', ' ') else: - # Find the maxima of an image (does not find minima). - # LIMITATIONS: With output_type=Segmented_Particles - # (watershed segmentation), some segmentation lines - # may be improperly placed if local maxima are suppressed - # by the tolerance. - mf = MaximumFinder() - if output_type == 'Single_Points': - output_type_param = mf.SINGLE_POINTS - elif output_type == 'Maxima_Within_Tolerance': - output_type_param = mf.IN_TOLERANCE - elif output_type == 'Segmented_Particles': - output_type_param = mf.SEGMENTED - elif output_type == 'List': - output_type_param = mf.LIST - elif output_type == 'Count': - output_type_param = mf.COUNT - # Get a new byteProcessor with a normal (uninverted) LUT where - # the marked points are set to 255 (Background 0). Pixels outside - # of the roi of the input image_processor_copy are not set. No - # output image is created for output types POINT_SELECTION, LIST - # and COUNT. In these cases findMaxima returns null. - byte_processor = mf.findMaxima( image_processor_copy, - noise_tolerance, - ImageProcessor.NO_THRESHOLD, - output_type_param, - exclude_edge_maxima, - False ) - # Invert the image or ROI. - byte_processor.invert() - if output_type == 'Segmented_Particles' and not light_background: - # Invert the values in this image's LUT (indexed color model). - byte_processor.invertLut() - image_plus = ImagePlus( "output", byte_processor ) - IJ.saveAs( image_plus, output_datatype, tmp_output_path ) -except Exception, e: - jython_utils.handle_error( error_log, str( e ) ) + output_type_str = 'output=%s' % output_type + options.append(output_type_str) + if exclude_edge_maxima: + options.append('exclude') + if light_background: + options.append('light') + # Run the command. + IJ.run(input_image_plus_copy, "Find Maxima...", "%s" % " ".join(options)) + results_table = analyzer.getResultsTable() + results_table.saveAs(tmp_output_path) +else: + # Find the maxima of an image (does not find minima). + # LIMITATIONS: With output_type=Segmented_Particles + # (watershed segmentation), some segmentation lines + # may be improperly placed if local maxima are suppressed + # by the tolerance. + mf = MaximumFinder() + if output_type == 'Single_Points': + output_type_param = mf.SINGLE_POINTS + elif output_type == 'Maxima_Within_Tolerance': + output_type_param = mf.IN_TOLERANCE + elif output_type == 'Segmented_Particles': + output_type_param = mf.SEGMENTED + elif output_type == 'List': + output_type_param = mf.LIST + elif output_type == 'Count': + output_type_param = mf.COUNT + # Get a new byteProcessor with a normal (uninverted) LUT where + # the marked points are set to 255 (Background 0). Pixels outside + # of the roi of the input image_processor_copy are not set. No + # output image is created for output types POINT_SELECTION, LIST + # and COUNT. In these cases findMaxima returns null. + byte_processor = mf.findMaxima(image_processor_copy, + noise_tolerance, + ImageProcessor.NO_THRESHOLD, + output_type_param, + exclude_edge_maxima, + False) + # Invert the image or ROI. + byte_processor.invert() + if output_type == 'Segmented_Particles' and not light_background: + # Invert the values in this image's LUT (indexed color model). + byte_processor.invertLut() + image_plus = ImagePlus("output", byte_processor) + IJ.saveAs(image_plus, output_datatype, tmp_output_path) |
b |
diff -r a84f2cbf091b -r 4c43ba752312 imagej2_macros.xml --- a/imagej2_macros.xml Tue Sep 17 17:08:08 2019 -0400 +++ b/imagej2_macros.xml Mon Sep 28 16:38:24 2020 +0000 |
b |
@@ -1,9 +1,9 @@ -<?xml version='1.0' encoding='UTF-8'?> <macros> <token name="@WRAPPER_VERSION@">3.0</token> <xml name="fiji_requirements"> <requirements> <requirement type="package" version="20170530">fiji</requirement> + <requirement type="package" version="3.4">grep</requirement> </requirements> </xml> <xml name="stdio"> @@ -16,7 +16,7 @@ </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_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> @@ -38,20 +38,45 @@ <param name="iterations" type="integer" value="1" min="1" max="100" label="Iterations" help="The number of times (1-100) erosion, dilation, opening, and closing are performed."/> <param name="count" type="integer" value="1" min="1" max="8" label="Count" help="The number of adjacent background pixels necessary (1-8) for erosion or dilation."/> <param name="black_background" type="select" label="Black background" help="If Yes, the background is black and the foreground is white (no implies the opposite)."> - <option value="no" selected="True">No</option> + <option value="no" selected="true">No</option> <option value="yes">Yes</option> </param> <param name="pad_edges_when_eroding" type="select" label="Pad edges when eroding" help="If Yes, eroding does not erode from the edges of the image."> - <option value="no" selected="True">No</option> + <option value="no" selected="true">No</option> <option value="yes">Yes</option> </param> </xml> <xml name="black_background_param"> <param name="black_background" type="select" label="Black background" help="If Yes, the background is black and the foreground is white (no implies the opposite)."> - <option value="no" selected="True">No</option> + <option value="no" selected="true">No</option> <option value="yes">Yes</option> </param> </xml> + <xml name="param_input"> + <param format="bmp,eps,gif,jpg,pcx,pgm,png,psd,tiff" name="input" type="data" label="Select image"/> + </xml> + <xml name="param_source_image"> + <param format="bmp,eps,gif,jpg,pcx,pgm,png,psd,tiff" name="source_image" type="data" label="Source image"/> + </xml> + <xml name="param_source_mask"> + <param format="bmp,eps,gif,jpg,pcx,pgm,png,psd,tiff" name="source_mask" type="data" label="Source mask"/> + </xml> + <xml name="param_target_image"> + <param format="bmp,eps,gif,jpg,pcx,pgm,png,psd,tiff" name="target_image" type="data" label="Target image"/> + </xml> + <xml name="param_target_mask"> + <param format="bmp,eps,gif,jpg,pcx,pgm,png,psd,tiff" name="target_mask" type="data" label="Target mask"/> + </xml> + <xml name="test_bunwarpj_raw_transform"> + <param name="target_image" value="dotblot.jpg"/> + <param name="source_image" value="blobs.gif"/> + <param name="target_raw_transformation" value="target_raw_transformation.txt"/> + <param name="source_raw_transformation" value="source_raw_transformation.txt"/> + </xml> + <xml name="test_target_source_images"> + <param name="target_image" value="dotblot.jpg"/> + <param name="source_image" value="blobs.gif"/> + </xml> <token name="@make_binary_args@"> --iterations $iterations --count $count |
b |
diff -r a84f2cbf091b -r 4c43ba752312 imagej2_make_binary.py --- a/imagej2_make_binary.py Tue Sep 17 17:08:08 2019 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 |
b |
@@ -1,59 +0,0 @@ -#!/usr/bin/env python -import argparse -import os -import shutil -import subprocess -import tempfile -import imagej2_base_utils - -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( '--iterations', dest='iterations', type=int, help='Iterations' ) -parser.add_argument( '--count', dest='count', type=int, help='Count' ) -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( '--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() - -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.output_datatype ) -# 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( None, 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 += ' %d' % args.iterations -cmd += ' %d' % args.count -cmd += ' %s' % args.black_background -cmd += ' %s' % args.pad_edges_when_eroding -cmd += ' %s' % tmp_output_path -cmd += ' %s' % args.output_datatype -# Run the command. -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_out, 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 ) |
b |
diff -r a84f2cbf091b -r 4c43ba752312 imagej2_make_binary_jython_script.py --- a/imagej2_make_binary_jython_script.py Tue Sep 17 17:08:08 2019 -0400 +++ b/imagej2_make_binary_jython_script.py Mon Sep 28 16:38:24 2020 +0000 |
[ |
@@ -1,37 +1,36 @@ -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[ -8 ] -input = sys.argv[ -7 ] -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 ] +error_log = sys.argv[-8] +input = sys.argv[-7] +iterations = int(sys.argv[-6]) +count = int(sys.argv[-5]) +black_background = sys.argv[-4] == 'yes' +pad_edges_when_eroding = sys.argv[-3] == 'yes' +tmp_output_path = sys.argv[-2] +output_datatype = sys.argv[-1] # Open the input image file. -input_image_plus = IJ.openImage( input ) +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: - # 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 ) +# Set binary options. +options = ['edm=Overwrite', 'iterations=%d' % iterations, 'count=%d' % count] +if pad_edges_when_eroding: + options.append('pad') +if black_background: + options.append('black') +options = ' '.join(options) +IJ.run(input_image_plus_copy, "Options...", options) - # Run the command. - IJ.run( input_image_plus_copy, "Make Binary", "" ) +# Run the command. +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: - jython_utils.handle_error( error_log, str( e ) ) +# Save the ImagePlus object as a new image. +IJ.saveAs(input_image_plus_copy, output_datatype, tmp_output_path) |
b |
diff -r a84f2cbf091b -r 4c43ba752312 imagej2_math.py --- a/imagej2_math.py Tue Sep 17 17:08:08 2019 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 |
[ |
@@ -1,69 +0,0 @@ -#!/usr/bin/env python -import argparse -import os -import shutil -import subprocess -import tempfile -import imagej2_base_utils - -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( '--operation', dest='operation', help='Operation' ) -parser.add_argument( '--expression', dest='expression', default=None, help='Expression' ) -parser.add_argument( '--bin_constant', dest='bin_constant', type=int, default=None, help='Constant of type binary integer' ) -parser.add_argument( '--float_constant', dest='float_constant', type=float, default=None, help='Constant of type float' ) -parser.add_argument( '--jython_script', dest='jython_script', help='Path to the Jython script' ) -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() - -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.output_datatype ) - -# 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( None, 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.operation -# Handle the expression, which must be enclosed in " if not None. -if args.expression in [ None, 'None' ]: - cmd += ' None' -else: - cmd += ' "%s"' % args.expression -cmd += imagej2_base_utils.handle_none_type( args.bin_constant, val_type='int' ) -cmd += imagej2_base_utils.handle_none_type( args.float_constant ) -cmd += ' %s' % tmp_output_path -cmd += ' %s' % args.output_datatype - -# Run the command. -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_out, 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 ) |
b |
diff -r a84f2cbf091b -r 4c43ba752312 imagej2_math_jython_script.py --- a/imagej2_math_jython_script.py Tue Sep 17 17:08:08 2019 -0400 +++ b/imagej2_math_jython_script.py Mon Sep 28 16:38:24 2020 +0000 |
[ |
@@ -1,78 +1,84 @@ -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[ -8 ] -input = sys.argv[ -7 ] -operation = sys.argv[ -6 ] -expression = sys.argv[ -5 ] -if sys.argv[ -4 ] in [ None, 'None' ]: +error_log = sys.argv[-8] +input_file = sys.argv[-7] +operation = sys.argv[-6] +expression = sys.argv[-5] +if sys.argv[-4] in [None, 'None']: bin_constant = None else: - bin_constant = int( sys.argv[ -4 ] ) -if sys.argv[ -3 ] in [ None, 'None' ]: + bin_constant = int(sys.argv[-4]) +if sys.argv[-3] in [None, 'None']: float_constant = None else: - float_constant = float( sys.argv[ -3 ] ) -tmp_output_path = sys.argv[ -2 ] -output_datatype = sys.argv[ -1 ] + float_constant = float(sys.argv[-3]) +tmp_output_path = sys.argv[-2] +output_datatype = sys.argv[-1] + +print("\nerror_log: %s\n" % str(error_log)) +print("\ninput_file: %s\n" % str(input_file)) +print("\noperation: %s\n" % str(operation)) +print("\nexpression: %s\n" % str(expression)) +print("\nbin_constant: %s\n" % str(bin_constant)) +print("\nfloat_constant: %s\n" % str(float_constant)) +print("\ntmp_output_path: %s\n" % str(tmp_output_path)) +print("\noutput_datatype: %s\n" % str(output_datatype)) # Open the input image file. -input_image_plus = IJ.openImage( input ) +input_image_plus = IJ.openImage(input_file) # Create a copy of the image. input_image_plus_copy = input_image_plus.duplicate() image_processor_copy = input_image_plus_copy.getProcessor() bit_depth = image_processor_copy.getBitDepth() -try: - if operation.find( '_' ) > 0: - # Square_Root. - new_operation = operation.replace( '_', ' ' ) - elif operation in [ 'Square', 'Log', 'Exp', 'Abs', 'Reciprocal' ]: - # Unfortunately some ImageJ commands require a "..." ending - # while others do not. There seems to be no pattern. - new_operation = '%s' % operation - else: - new_operation = '%s...' % operation +if operation.find('_') > 0: + # Square_Root. + new_operation = operation.replace('_', ' ') +elif operation in ['Square', 'Log', 'Exp', 'Abs', 'Reciprocal']: + # Unfortunately some ImageJ commands require a "..." ending + # while others do not. There seems to be no pattern. + new_operation = '%s' % operation +else: + new_operation = '%s...' % operation - if operation == 'Macro': - # Apply the macro code to the image via a call to it's - # ImageProcessor since this option does not work using - # the IJ.run() method. - new_expression = expression.lstrip( '"' ).rstrip( '"' ) - options = 'code=%s' % new_expression - image_processor_copy.applyMacro( new_expression ) - elif operation == 'Min': - # Min does not work without using the ImageProcessor. - image_processor_copy.min( float_constant ) - elif operation == 'Max': - # Max does not work without using the ImageProcessor. - image_processor_copy.max( float_constant ) - elif operation == 'Abs': - if bit_depth not in [ 16, 32 ]: - # Convert the image to 32-bit. - IJ.run( input_image_plus_copy, "32-bit", "" ) - IJ.run( input_image_plus_copy, new_operation, "" ) - elif operation == 'Reciprocal': - if bit_depth != 32: - # Convert the image to 32 bit. - IJ.run( input_image_plus_copy, "32-bit", "" ) - IJ.run( input_image_plus_copy, new_operation, "" ) +if operation == 'Macro': + # Apply the macro code to the image via a call to it's + # ImageProcessor since this option does not work using + # the IJ.run() method. + new_expression = expression.lstrip('"').rstrip('"') + options = 'code=%s' % new_expression + image_processor_copy.applyMacro(new_expression) +elif operation == 'Min': + # Min does not work without using the ImageProcessor. + image_processor_copy.min(float_constant) +elif operation == 'Max': + # Max does not work without using the ImageProcessor. + image_processor_copy.max(float_constant) +elif operation == 'Abs': + if bit_depth not in [16, 32]: + # Convert the image to 32-bit. + IJ.run(input_image_plus_copy, "32-bit", "") + IJ.run(input_image_plus_copy, new_operation, "") +elif operation == 'Reciprocal': + if bit_depth != 32: + # Convert the image to 32 bit. + IJ.run(input_image_plus_copy, "32-bit", "") + IJ.run(input_image_plus_copy, new_operation, "") +else: + if operation in ['AND', 'OR', 'XOR']: + # Value is a binary number. + options = 'value=%d' % bin_constant + elif operation in ['Log', 'Exp', 'Square', 'Square_Root']: + # No constant value. + options = '' else: - if operation in [ 'AND', 'OR', 'XOR' ]: - # Value is a binary number. - options = 'value=%d' % bin_constant - elif operation in [ 'Log', 'Exp', 'Square', 'Square_Root' ]: - # No constant value. - options = '' - else: - # Value is a floating point number. - options = 'value=%.3f' % float_constant - IJ.run( input_image_plus_copy, "%s" % new_operation, "%s" % options ) - # 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 ) ) + # Value is a floating point number. + options = 'value=%.3f' % float_constant + IJ.run(input_image_plus_copy, "%s" % new_operation, "%s" % options) +# Save the ImagePlus object as a new image. +IJ.saveAs(input_image_plus_copy, output_datatype, tmp_output_path) |
b |
diff -r a84f2cbf091b -r 4c43ba752312 imagej2_noise.py --- a/imagej2_noise.py Tue Sep 17 17:08:08 2019 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 |
b |
@@ -1,84 +0,0 @@ -#!/usr/bin/env python -import argparse -import os -import shutil -import subprocess -import tempfile -import imagej2_base_utils - -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( '--output', dest='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 ) - - # 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( None, 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 += imagej2_base_utils.handle_none_type( args.standard_deviation ) - cmd += imagej2_base_utils.handle_none_type( args.radius ) - cmd += imagej2_base_utils.handle_none_type( args.threshold ) - cmd += ' %s' % args.which_outliers - cmd += ' %s' % args.randomj - cmd += imagej2_base_utils.handle_none_type( args.trials ) - cmd += imagej2_base_utils.handle_none_type( args.probability ) - cmd += imagej2_base_utils.handle_none_type( args.lammbda ) - cmd += imagej2_base_utils.handle_none_type( args.order, val_type='int' ) - cmd += imagej2_base_utils.handle_none_type( args.mean ) - cmd += imagej2_base_utils.handle_none_type( args.sigma ) - cmd += imagej2_base_utils.handle_none_type( args.min ) - cmd += imagej2_base_utils.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_out, 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 ) |
b |
diff -r a84f2cbf091b -r 4c43ba752312 imagej2_noise_jython_script.py --- a/imagej2_noise_jython_script.py Tue Sep 17 17:08:08 2019 -0400 +++ b/imagej2_noise_jython_script.py Mon Sep 28 16:38:24 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) |
b |
diff -r a84f2cbf091b -r 4c43ba752312 imagej2_shadows.py --- a/imagej2_shadows.py Tue Sep 17 17:08:08 2019 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 |
b |
@@ -1,59 +0,0 @@ -#!/usr/bin/env python -import argparse -import os -import shutil -import subprocess -import tempfile -import imagej2_base_utils - -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( '--direction', dest='direction', help='Direction' ) -parser.add_argument( '--jython_script', dest='jython_script', help='Path to the Jython script' ) -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() - -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.output_datatype ) - -# 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( None, 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.direction -cmd += ' %s' % tmp_output_path -cmd += ' %s' % args.output_datatype - -# Run the command. -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_out, 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 ) |
b |
diff -r a84f2cbf091b -r 4c43ba752312 imagej2_shadows_jython_script.py --- a/imagej2_shadows_jython_script.py Tue Sep 17 17:08:08 2019 -0400 +++ b/imagej2_shadows_jython_script.py Mon Sep 28 16:38:24 2020 +0000 |
[ |
@@ -1,26 +1,23 @@ -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 ] +error_log = sys.argv[-5] +input_file = 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 ) +input_image_plus = IJ.openImage(input_file) # 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 ) ) +# 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) |
b |
diff -r a84f2cbf091b -r 4c43ba752312 imagej2_sharpen.py --- a/imagej2_sharpen.py Tue Sep 17 17:08:08 2019 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 |
b |
@@ -1,57 +0,0 @@ -#!/usr/bin/env python -import argparse -import os -import shutil -import subprocess -import tempfile -import imagej2_base_utils - -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( '--jython_script', dest='jython_script', help='Path to the Jython script' ) -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() - -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.output_datatype ) - -# 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( None, 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' % tmp_output_path -cmd += ' %s' % args.output_datatype - -# Run the command. -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_out, 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 ) |
b |
diff -r a84f2cbf091b -r 4c43ba752312 imagej2_sharpen.xml --- a/imagej2_sharpen.xml Tue Sep 17 17:08:08 2019 -0400 +++ b/imagej2_sharpen.xml Mon Sep 28 16:38:24 2020 +0000 |
[ |
@@ -1,30 +1,41 @@ -<?xml version='1.0' encoding='UTF-8'?> <tool id="imagej2_sharpen" name="Sharpen" version="@WRAPPER_VERSION@.0"> <description></description> <macros> <import>imagej2_macros.xml</import> </macros> - <expand macro="fiji_requirements" /> - <command> -<![CDATA[ - python $__tool_directory__/imagej2_sharpen.py - --input "$input" - --input_datatype $input.ext - --jython_script $__tool_directory__/imagej2_sharpen_jython_script.py - --output_datatype $output.ext - --output "$output" -]]> - </command> + <expand macro="fiji_requirements"/> + <command detect_errors="exit_code"><![CDATA[ +#import os +#set error_log = 'output_log.txt' +touch '$error_log' && +#set input_sans_ext = $os.path.splitext($os.path.basename($input.file_name))[0] +#set input_with_ext = '.'.join([input_sans_ext, $input.ext]) +ln -s '$input.file_name' '$input_with_ext' && +#set output_filename = '.'.join(['output', $input.ext]) +touch '$output_filename' && +ImageJ --ij2 --headless --debug +--jython '$__tool_directory__/imagej2_sharpen_jython_script.py' +'$error_log' +'$input_with_ext' +'$output_filename' +'$input.ext' +&>'$error_log'; +if [[ $? -ne 0 ]]; then + cat '$error_log' >&2; +else + mv '$output_filename' '$output'; +fi +]]></command> <inputs> - <param format="bmp,eps,gif,jpg,pcx,pgm,png,psd,tiff" name="input" type="data" label="Select image"/> + <expand macro="param_input"/> </inputs> <outputs> - <data name="output" format_source="input" label="${tool.name} on ${on_string}"/> + <data name="output" format_source="input"/> </outputs> <tests> <test> - <param name="input" value="blobs.gif" /> - <output name="output" file="blobs_sharpen.gif" compare="sim_size" /> + <param name="input" value="blobs.gif"/> + <output name="output" file="blobs_sharpen.gif" compare="sim_size"/> </test> </tests> <help> @@ -45,5 +56,5 @@ ]]> </help> - <expand macro="fiji_headless_citations" /> + <expand macro="fiji_headless_citations"/> </tool> |
b |
diff -r a84f2cbf091b -r 4c43ba752312 imagej2_sharpen_jython_script.py --- a/imagej2_sharpen_jython_script.py Tue Sep 17 17:08:08 2019 -0400 +++ b/imagej2_sharpen_jython_script.py Mon Sep 28 16:38:24 2020 +0000 |
[ |
@@ -1,25 +1,22 @@ -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[ -4 ] -input = sys.argv[ -3 ] -tmp_output_path = sys.argv[ -2 ] -output_datatype = sys.argv[ -1 ] +error_log = sys.argv[-4] +input_file = 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 ) +input_image_plus = IJ.openImage(input_file) # 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, "Sharpen", "" ) - # 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 ) ) +# Run the command. +IJ.run(input_image_plus_copy, "Sharpen", "") +# Save the ImagePlus object as a new image. +IJ.saveAs(input_image_plus_copy, output_datatype, tmp_output_path) |
b |
diff -r a84f2cbf091b -r 4c43ba752312 imagej2_skeletonize3d.py --- a/imagej2_skeletonize3d.py Tue Sep 17 17:08:08 2019 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 |
b |
@@ -1,53 +0,0 @@ -#!/usr/bin/env python -import argparse -import os -import shutil -import subprocess -import tempfile -import imagej2_base_utils - -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( '--black_background', dest='black_background', help='Black background' ) -parser.add_argument( '--jython_script', dest='jython_script', help='Path to the Jython script' ) -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() - -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.output_datatype ) -# 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( None, 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.black_background -cmd += ' %s' % tmp_output_path -cmd += ' %s' % args.output_datatype -# Run the command. -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_out, 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 ) |
b |
diff -r a84f2cbf091b -r 4c43ba752312 imagej2_skeletonize3d_jython_script.py --- a/imagej2_skeletonize3d_jython_script.py Tue Sep 17 17:08:08 2019 -0400 +++ b/imagej2_skeletonize3d_jython_script.py Mon Sep 28 16:38:24 2020 +0000 |
[ |
@@ -1,36 +1,36 @@ -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 ] -black_background = jython_utils.asbool( sys.argv[ -3 ] ) -tmp_output_path = sys.argv[ -2 ] -output_datatype = sys.argv[ -1 ] +error_log = sys.argv[-5] +input_file = sys.argv[-4] +black_background = sys.argv[-3] == 'yes' +tmp_output_path = sys.argv[-2] +output_datatype = sys.argv[-1] # Open the input image file. -input_image_plus = IJ.openImage( input ) +input_image_plus = IJ.openImage(input_file) # Create a copy of the image. input_image_plus_copy = input_image_plus.duplicate() image_processor_copy = input_image_plus_copy.getProcessor() -try: - # Set binary options. - options = jython_utils.get_binary_options( black_background=black_background ) - IJ.run( input_image_plus_copy, "Options...", options ) +# Set binary options. +options = ['edm=Overwrite', 'iterations=1', 'count=1'] +if (black_background): + options.append('black') +options = " ".join(options) +IJ.run(input_image_plus_copy, "Options...", options) - # 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", "" ) +# 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", "") - # Run the command. - IJ.run( input_image_plus_copy, "Skeletonize (2D/3D)", "" ) +# Run the command. +IJ.run(input_image_plus_copy, "Skeletonize (2D/3D)", "") - # 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 ) ) +# Save the ImagePlus object as a new image. +IJ.saveAs(input_image_plus_copy, output_datatype, tmp_output_path) |
b |
diff -r a84f2cbf091b -r 4c43ba752312 imagej2_smooth.py --- a/imagej2_smooth.py Tue Sep 17 17:08:08 2019 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 |
b |
@@ -1,57 +0,0 @@ -#!/usr/bin/env python -import argparse -import os -import shutil -import subprocess -import tempfile -import imagej2_base_utils - -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( '--jython_script', dest='jython_script', help='Path to the Jython script' ) -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() - -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.output_datatype ) - -# 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( None, 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' % tmp_output_path -cmd += ' %s' % args.output_datatype - -# Run the command. -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_out, 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 ) |
b |
diff -r a84f2cbf091b -r 4c43ba752312 imagej2_smooth_jython_script.py --- a/imagej2_smooth_jython_script.py Tue Sep 17 17:08:08 2019 -0400 +++ b/imagej2_smooth_jython_script.py Mon Sep 28 16:38:24 2020 +0000 |
[ |
@@ -1,25 +1,22 @@ -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[ -4 ] -input = sys.argv[ -3 ] -tmp_output_path = sys.argv[ -2 ] -output_datatype = sys.argv[ -1 ] +error_log = sys.argv[-4] +input = 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 ) +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, "Smooth", "" ) - # 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 ) ) +# Run the command. +IJ.run(input_image_plus_copy, "Smooth", "") +# Save the ImagePlus object as a new image. +IJ.saveAs(input_image_plus_copy, output_datatype, tmp_output_path) |
b |
diff -r a84f2cbf091b -r 4c43ba752312 imagej2_watershed_binary.py --- a/imagej2_watershed_binary.py Tue Sep 17 17:08:08 2019 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 |
b |
@@ -1,53 +0,0 @@ -#!/usr/bin/env python -import argparse -import os -import shutil -import subprocess -import tempfile -import imagej2_base_utils - -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( '--black_background', dest='black_background', help='Black background' ) -parser.add_argument( '--jython_script', dest='jython_script', help='Path to the Jython script' ) -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() - -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.output_datatype ) -# 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( None, 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.black_background -cmd += ' %s' % tmp_output_path -cmd += ' %s' % args.output_datatype -# Run the command. -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_out, 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 ) |
b |
diff -r a84f2cbf091b -r 4c43ba752312 imagej2_watershed_binary_jython_script.py --- a/imagej2_watershed_binary_jython_script.py Tue Sep 17 17:08:08 2019 -0400 +++ b/imagej2_watershed_binary_jython_script.py Mon Sep 28 16:38:24 2020 +0000 |
[ |
@@ -1,36 +1,36 @@ -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 ] -black_background = jython_utils.asbool( sys.argv[ -3 ] ) -tmp_output_path = sys.argv[ -2 ] -output_datatype = sys.argv[ -1 ] +error_log = sys.argv[-5] +input = sys.argv[-4] +black_background = sys.argv[-3] == 'yes' +tmp_output_path = sys.argv[-2] +output_datatype = sys.argv[-1] # Open the input image file. -input_image_plus = IJ.openImage( input ) +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: - # Set binary options. - options = jython_utils.get_binary_options( black_background=black_background ) - IJ.run( input_image_plus_copy, "Options...", options ) +# Set binary options. +options = ['edm=Overwrite', 'iterations=1', 'count=1'] +if (black_background): + options.append('black') +options = " ".join(options) +IJ.run(input_image_plus_copy, "Options...", options) - # 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", "" ) +# 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", "") - # Run the command. - IJ.run( input_image_plus_copy, "Watershed", "" ) +# Run the command. +IJ.run(input_image_plus_copy, "Watershed", "") - # 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 ) ) +# Save the ImagePlus object as a new image. +IJ.saveAs(input_image_plus_copy, output_datatype, tmp_output_path) |
b |
diff -r a84f2cbf091b -r 4c43ba752312 jython_utils.py --- a/jython_utils.py Tue Sep 17 17:08:08 2019 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 |
[ |
@@ -1,48 +0,0 @@ -import imagej2_base_utils -from ij import IJ - -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 - # registered image, 2) the target image and 3) the black/white warp - # image. When running bUnwarpJ from the command line (as these - # Galaxy wrappers do) the initial call to IJ.openImage() (to open the - # registered source and target images produced by bUnwarpJ) in the - # tool's jython_script.py returns an ImagePlus object with a single - # slice which is the "generally undesired" slice 3 discussed above. - # However, a call to IJ.saveAs() will convert the single-slice TIFF - # into a 3-slice TIFF image stack (as described above) if the selected - # format for saving is TIFF. Galaxy supports only single-layered - # images, so to work around this behavior, we have to convert the - # image to something other than TIFF so that slices are eliminated. - # We can then convert back to TIFF for saving. There might be a way - # to do this without converting twice, but I spent a lot of time looking - # and I have yet to discover it. - tmp_dir = imagej2_base_utils.get_temp_dir() - tmp_out_png_path = imagej2_base_utils.get_temporary_image_path( tmp_dir, 'png' ) - 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 ) - -def handle_error( error_log, msg ): - # Java writes a lot of stuff to stderr, so the received error_log - # will log actual errors. - elh = open( error_log, 'wb' ) - elh.write( msg ) - elh.close() |
b |
diff -r a84f2cbf091b -r 4c43ba752312 test-data/analyze_particles_masks.gif |
b |
Binary file test-data/analyze_particles_masks.gif has changed |
b |
diff -r a84f2cbf091b -r 4c43ba752312 test-data/analyze_particles_nothing.tabular --- a/test-data/analyze_particles_nothing.tabular Tue Sep 17 17:08:08 2019 -0400 +++ b/test-data/analyze_particles_nothing.tabular Mon Sep 28 16:38:24 2020 +0000 |
b |
@@ -29,38 +29,36 @@ 28 55 255 255 255 29 116 255 255 255 30 172 255 255 255 -31 103 255 255 255 +31 191 255 255 255 32 4 255 255 255 33 60 255 255 255 34 198 255 255 255 35 187 255 255 255 36 7 255 255 255 37 85 255 255 255 -38 80 255 255 255 -39 75 255 255 255 -40 103 255 255 255 -41 151 255 255 255 -42 52 255 255 255 -43 122 255 255 255 -44 129 255 255 255 -45 77 255 255 255 -46 171 255 255 255 -47 117 255 255 255 -48 207 255 255 255 -49 119 255 255 255 -50 181 255 255 255 -51 22 255 255 255 -52 49 255 255 255 -53 150 255 255 255 -54 191 255 255 255 -55 170 255 255 255 -56 64 255 255 255 -57 174 255 255 255 -58 270 255 255 255 -59 87 255 255 255 -60 69 255 255 255 -61 1 255 255 255 -62 29 255 255 255 -63 25 255 255 255 -64 16 255 255 255 -65 15 255 255 255 +38 75 255 255 255 +39 283 255 255 255 +40 151 255 255 255 +41 52 255 255 255 +42 122 255 255 255 +43 129 255 255 255 +44 77 255 255 255 +45 117 255 255 255 +46 207 255 255 255 +47 119 255 255 255 +48 181 255 255 255 +49 22 255 255 255 +50 49 255 255 255 +51 150 255 255 255 +52 191 255 255 255 +53 170 255 255 255 +54 64 255 255 255 +55 174 255 255 255 +56 270 255 255 255 +57 87 255 255 255 +58 69 255 255 255 +59 1 255 255 255 +60 29 255 255 255 +61 25 255 255 255 +62 16 255 255 255 +63 15 255 255 255 |
b |
diff -r a84f2cbf091b -r 4c43ba752312 test-data/analyze_particles_outlines.gif |
b |
Binary file test-data/analyze_particles_outlines.gif has changed |
b |
diff -r a84f2cbf091b -r 4c43ba752312 test-data/basic.tabular --- a/test-data/basic.tabular Tue Sep 17 17:08:08 2019 -0400 +++ b/test-data/basic.tabular Mon Sep 28 16:38:24 2020 +0000 |
b |
@@ -1,2 +1,64 @@ # Branches Junctions End-point Voxels Junction Voxels Slab Voxels Average branch length Triple Points Quadruple Points Maximum Branch Length -96 60 7 120 1246 17.344 56 3 70.882 +1 0 2 0 5 6.000 0 0 6.000 +1 0 2 0 3 4.000 0 0 4.000 +0 0 1 0 0 0.000 0 0 0.000 +1 0 2 0 2 3.000 0 0 3.000 +0 0 1 0 0 0.000 0 0 0.000 +1 0 2 0 1 2.414 0 0 2.414 +1 0 2 0 6 8.243 0 0 8.243 +1 0 2 0 7 9.243 0 0 9.243 +1 0 2 0 0 1.414 0 0 1.414 +0 0 1 0 0 0.000 0 0 0.000 +0 0 1 0 0 0.000 0 0 0.000 +1 0 2 0 1 2.000 0 0 2.000 +0 0 1 0 0 0.000 0 0 0.000 +1 0 2 0 0 1.000 0 0 1.000 +1 0 2 0 3 4.414 0 0 4.414 +0 0 1 0 0 0.000 0 0 0.000 +1 0 2 0 3 4.414 0 0 4.414 +1 0 2 0 0 1.000 0 0 1.000 +0 0 1 0 0 0.000 0 0 0.000 +1 0 2 0 8 9.000 0 0 9.000 +1 0 2 0 1 2.828 0 0 2.828 +0 0 1 0 0 0.000 0 0 0.000 +1 0 2 0 0 1.000 0 0 1.000 +1 0 2 0 15 17.243 0 0 17.243 +1 0 2 0 2 3.828 0 0 3.828 +1 0 2 0 2 3.828 0 0 3.828 +1 0 2 0 0 1.000 0 0 1.000 +0 0 1 0 0 0.000 0 0 0.000 +1 0 2 0 11 14.485 0 0 14.485 +1 0 2 0 9 10.828 0 0 10.828 +1 0 2 0 8 9.828 0 0 9.828 +1 0 2 0 0 1.000 0 0 1.000 +1 0 2 0 2 4.243 0 0 4.243 +0 0 1 0 0 0.000 0 0 0.000 +1 0 2 0 0 1.414 0 0 1.414 +1 0 2 0 1 2.000 0 0 2.000 +1 0 2 0 0 1.000 0 0 1.000 +1 0 2 0 7 10.071 0 0 10.071 +1 0 2 0 7 8.414 0 0 8.414 +0 0 1 0 0 0.000 0 0 0.000 +1 0 2 0 6 7.414 0 0 7.414 +0 0 1 0 0 0.000 0 0 0.000 +1 0 2 0 4 5.414 0 0 5.414 +1 0 2 0 0 1.000 0 0 1.000 +0 0 1 0 0 0.000 0 0 0.000 +1 0 2 0 8 11.071 0 0 11.071 +0 0 1 0 0 0.000 0 0 0.000 +1 0 2 0 0 1.414 0 0 1.414 +1 0 2 0 0 1.414 0 0 1.414 +1 0 2 0 0 1.000 0 0 1.000 +1 0 2 0 3 4.828 0 0 4.828 +0 0 1 0 0 0.000 0 0 0.000 +1 0 2 0 0 1.000 0 0 1.000 +1 0 2 0 4 5.828 0 0 5.828 +1 0 2 0 0 1.414 0 0 1.414 +0 0 1 0 0 0.000 0 0 0.000 +1 0 2 0 0 1.000 0 0 1.000 +1 0 2 0 5 7.243 0 0 7.243 +1 0 2 0 0 1.414 0 0 1.414 +1 0 2 0 4 5.000 0 0 5.000 +1 0 2 0 2 3.000 0 0 3.000 +1 0 2 0 1 2.000 0 0 2.000 +1 0 2 0 3 4.000 0 0 4.000 |
b |
diff -r a84f2cbf091b -r 4c43ba752312 test-data/blobs_black_edm.gif |
b |
Binary file test-data/blobs_black_edm.gif has changed |
b |
diff -r a84f2cbf091b -r 4c43ba752312 test-data/blobs_edm.gif |
b |
Binary file test-data/blobs_edm.gif has changed |
b |
diff -r a84f2cbf091b -r 4c43ba752312 test-data/blobs_equalize.gif |
b |
Binary file test-data/blobs_equalize.gif has changed |
b |
diff -r a84f2cbf091b -r 4c43ba752312 test-data/blobs_find_edges.gif |
b |
Binary file test-data/blobs_find_edges.gif has changed |
b |
diff -r a84f2cbf091b -r 4c43ba752312 test-data/blobs_log.gif |
b |
Binary file test-data/blobs_log.gif has changed |
b |
diff -r a84f2cbf091b -r 4c43ba752312 test-data/blobs_min.gif |
b |
Binary file test-data/blobs_min.gif has changed |
b |
diff -r a84f2cbf091b -r 4c43ba752312 test-data/blobs_multiply.gif |
b |
Binary file test-data/blobs_multiply.gif has changed |
b |
diff -r a84f2cbf091b -r 4c43ba752312 test-data/blobs_normalize.gif |
b |
Binary file test-data/blobs_normalize.gif has changed |
b |
diff -r a84f2cbf091b -r 4c43ba752312 test-data/blobs_northwest.gif |
b |
Binary file test-data/blobs_northwest.gif has changed |
b |
diff -r a84f2cbf091b -r 4c43ba752312 test-data/blobs_saturate.gif |
b |
Binary file test-data/blobs_saturate.gif has changed |
b |
diff -r a84f2cbf091b -r 4c43ba752312 test-data/blobs_segmented.gif |
b |
Binary file test-data/blobs_segmented.gif has changed |
b |
diff -r a84f2cbf091b -r 4c43ba752312 test-data/blobs_single_points.gif |
b |
Binary file test-data/blobs_single_points.gif has changed |
b |
diff -r a84f2cbf091b -r 4c43ba752312 test-data/blobs_square.gif |
b |
Binary file test-data/blobs_square.gif has changed |
b |
diff -r a84f2cbf091b -r 4c43ba752312 test-data/blobs_tolerance.gif |
b |
Binary file test-data/blobs_tolerance.gif has changed |
b |
diff -r a84f2cbf091b -r 4c43ba752312 test-data/blobs_watershed_binary.gif |
b |
Binary file test-data/blobs_watershed_binary.gif has changed |
b |
diff -r a84f2cbf091b -r 4c43ba752312 test-data/elastic_trans_registered_source1.png |
b |
Binary file test-data/elastic_trans_registered_source1.png has changed |
b |
diff -r a84f2cbf091b -r 4c43ba752312 test-data/largest_shortest_path_basic.tabular --- a/test-data/largest_shortest_path_basic.tabular Tue Sep 17 17:08:08 2019 -0400 +++ b/test-data/largest_shortest_path_basic.tabular Mon Sep 28 16:38:24 2020 +0000 |
b |
@@ -1,2 +1,64 @@ # Branches Junctions End-point Voxels Junction Voxels Slab Voxels Average branch length Triple Points Quadruple Points Maximum Branch Length Longest Shortest Path spx spy spz -96 60 7 120 1246 17.344 56 3 70.882 207.380 135 137 0 +1 0 2 0 5 6.000 0 0 6.000 6.000 0 18 0 +1 0 2 0 3 4.000 0 0 4.000 4.000 2 130 0 +0 0 1 0 0 0.000 0 0 0.000 0.000 4 25 0 +1 0 2 0 2 3.000 0 0 3.000 3.000 4 56 0 +0 0 1 0 0 0.000 0 0 0.000 0.000 4 79 0 +1 0 2 0 1 2.414 0 0 2.414 2.414 9 94 0 +1 0 2 0 6 8.243 0 0 8.243 8.243 12 4 0 +1 0 2 0 7 9.243 0 0 9.243 9.243 16 126 0 +1 0 2 0 0 1.414 0 0 1.414 1.414 16 32 0 +0 0 1 0 0 0.000 0 0 0.000 0.000 19 49 0 +0 0 1 0 0 0.000 0 0 0.000 0.000 20 69 0 +1 0 2 0 1 2.000 0 0 2.000 2.000 24 98 0 +0 0 1 0 0 0.000 0 0 0.000 0.000 25 14 0 +1 0 2 0 0 1.000 0 0 1.000 1.000 25 137 0 +1 0 2 0 3 4.414 0 0 4.414 4.414 38 2 0 +0 0 1 0 0 0.000 0 0 0.000 0.000 34 69 0 +1 0 2 0 3 4.414 0 0 4.414 4.414 35 126 0 +1 0 2 0 0 1.000 0 0 1.000 1.000 36 47 0 +0 0 1 0 0 0.000 0 0 0.000 0.000 37 83 0 +1 0 2 0 8 9.000 0 0 9.000 9.000 46 143 0 +1 0 2 0 1 2.828 0 0 2.828 2.828 42 22 0 +0 0 1 0 0 0.000 0 0 0.000 0.000 43 137 0 +1 0 2 0 0 1.000 0 0 1.000 1.000 47 65 0 +1 0 2 0 15 17.243 0 0 17.243 17.243 51 83 0 +1 0 2 0 2 3.828 0 0 3.828 3.828 56 40 0 +1 0 2 0 2 3.828 0 0 3.828 3.828 59 122 0 +1 0 2 0 0 1.000 0 0 1.000 1.000 58 63 0 +0 0 1 0 0 0.000 0 0 0.000 0.000 60 6 0 +1 0 2 0 11 14.485 0 0 14.485 14.485 73 68 0 +1 0 2 0 9 10.828 0 0 10.828 10.828 77 143 0 +1 0 2 0 8 9.828 0 0 9.828 9.828 79 46 0 +1 0 2 0 0 1.000 0 0 1.000 1.000 73 112 0 +1 0 2 0 2 4.243 0 0 4.243 4.243 78 91 0 +0 0 1 0 0 0.000 0 0 0.000 0.000 77 12 0 +1 0 2 0 0 1.414 0 0 1.414 1.414 78 32 0 +1 0 2 0 1 2.000 0 0 2.000 2.000 77 134 0 +1 0 2 0 0 1.000 0 0 1.000 1.000 87 5 0 +1 0 2 0 7 10.071 0 0 10.071 10.071 95 78 0 +1 0 2 0 7 8.414 0 0 8.414 8.414 101 56 0 +0 0 1 0 0 0.000 0 0 0.000 0.000 94 41 0 +1 0 2 0 6 7.414 0 0 7.414 7.414 103 142 0 +0 0 1 0 0 0.000 0 0 0.000 0.000 98 18 0 +1 0 2 0 4 5.414 0 0 5.414 5.414 104 131 0 +1 0 2 0 0 1.000 0 0 1.000 1.000 101 103 0 +0 0 1 0 0 0.000 0 0 0.000 0.000 106 88 0 +1 0 2 0 8 11.071 0 0 11.071 11.071 112 28 0 +0 0 1 0 0 0.000 0 0 0.000 0.000 111 9 0 +1 0 2 0 0 1.414 0 0 1.414 1.414 116 115 0 +1 0 2 0 0 1.414 0 0 1.414 1.414 121 39 0 +1 0 2 0 0 1.000 0 0 1.000 1.000 120 95 0 +1 0 2 0 3 4.828 0 0 4.828 4.828 123 16 0 +0 0 1 0 0 0.000 0 0 0.000 0.000 125 54 0 +1 0 2 0 0 1.000 0 0 1.000 1.000 126 72 0 +1 0 2 0 4 5.828 0 0 5.828 5.828 134 143 0 +1 0 2 0 0 1.414 0 0 1.414 1.414 131 104 0 +0 0 1 0 0 0.000 0 0 0.000 0.000 131 26 0 +1 0 2 0 0 1.000 0 0 1.000 1.000 131 129 0 +1 0 2 0 5 7.243 0 0 7.243 7.243 140 84 0 +1 0 2 0 0 1.414 0 0 1.414 1.414 138 41 0 +1 0 2 0 4 5.000 0 0 5.000 5.000 139 10 0 +1 0 2 0 2 3.000 0 0 3.000 3.000 141 61 0 +1 0 2 0 1 2.000 0 0 2.000 2.000 143 71 0 +1 0 2 0 3 4.000 0 0 4.000 4.000 142 115 0 |
b |
diff -r a84f2cbf091b -r 4c43ba752312 test-data/raw_trans_registered_source1.png |
b |
Binary file test-data/raw_trans_registered_source1.png has changed |
b |
diff -r a84f2cbf091b -r 4c43ba752312 test-data/registered_source1.png |
b |
Binary file test-data/registered_source1.png has changed |
b |
diff -r a84f2cbf091b -r 4c43ba752312 test-data/registered_source2.png |
b |
Binary file test-data/registered_source2.png has changed |
b |
diff -r a84f2cbf091b -r 4c43ba752312 test-data/registered_target1.png |
b |
Binary file test-data/registered_target1.png has changed |
b |
diff -r a84f2cbf091b -r 4c43ba752312 test-data/registered_target2.png |
b |
Binary file test-data/registered_target2.png has changed |
b |
diff -r a84f2cbf091b -r 4c43ba752312 test-data/skeletonized_blobs.gif |
b |
Binary file test-data/skeletonized_blobs.gif has changed |
b |
diff -r a84f2cbf091b -r 4c43ba752312 test-data/source_elastic_transformation_out.txt --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test-data/source_elastic_transformation_out.txt Mon Sep 28 16:38:24 2020 +0000 |
b |
@@ -0,0 +1,5 @@ +Intervals=4 + +X Coeffs ----------------------------------- + +Y Coeffs ----------------------------------- |
b |
diff -r a84f2cbf091b -r 4c43ba752312 test-data/target_elastic_transformation_out.txt --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test-data/target_elastic_transformation_out.txt Mon Sep 28 16:38:24 2020 +0000 |
b |
@@ -0,0 +1,5 @@ +Intervals=4 + +X Coeffs ----------------------------------- + +Y Coeffs ----------------------------------- |