# HG changeset patch
# User imgteam
# Date 1601312213 0
# Node ID 8d357579e407bc6aa7a41fd4d4e48a4b3c2e8079
# Parent 1bf7e70e67f9f2f7ccb9d310b0b7957821c523af
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 2afb24f3c81d625312186750a714d702363012b5"
diff -r 1bf7e70e67f9 -r 8d357579e407 imagej2_adjust_threshold_binary.py
--- a/imagej2_adjust_threshold_binary.py Tue Sep 17 16:56:02 2019 -0400
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -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 )
diff -r 1bf7e70e67f9 -r 8d357579e407 imagej2_adjust_threshold_binary_jython_script.py
--- a/imagej2_adjust_threshold_binary_jython_script.py Tue Sep 17 16:56:02 2019 -0400
+++ b/imagej2_adjust_threshold_binary_jython_script.py Mon Sep 28 16:56:53 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)
diff -r 1bf7e70e67f9 -r 8d357579e407 imagej2_analyze_particles_binary.py
--- a/imagej2_analyze_particles_binary.py Tue Sep 17 16:56:02 2019 -0400
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -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 )
diff -r 1bf7e70e67f9 -r 8d357579e407 imagej2_analyze_particles_binary_jython_script.py
--- a/imagej2_analyze_particles_binary_jython_script.py Tue Sep 17 16:56:02 2019 -0400
+++ b/imagej2_analyze_particles_binary_jython_script.py Mon Sep 28 16:56:53 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)
diff -r 1bf7e70e67f9 -r 8d357579e407 imagej2_analyze_skeleton.py
--- a/imagej2_analyze_skeleton.py Tue Sep 17 16:56:02 2019 -0400
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -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 )
diff -r 1bf7e70e67f9 -r 8d357579e407 imagej2_analyze_skeleton_jython_script.py
--- a/imagej2_analyze_skeleton_jython_script.py Tue Sep 17 16:56:02 2019 -0400
+++ b/imagej2_analyze_skeleton_jython_script.py Mon Sep 28 16:56:53 2020 +0000
@@ -1,147 +1,148 @@
-import jython_utils
import math
import sys
+
from ij import IJ
from sc.fiji.analyzeSkeleton import AnalyzeSkeleton_
-BASIC_NAMES = [ 'Branches', 'Junctions', 'End-point Voxels',
- 'Junction Voxels', 'Slab Voxels', 'Average branch length',
- 'Triple Points', 'Quadruple Points', 'Maximum Branch Length' ]
-DETAIL_NAMES = [ 'Skeleton ID', 'Branch length', 'V1 x', 'V1 y', 'V1 z', 'V2 x',
- 'V2 y', 'V2 z', 'Euclidean distance' ]
+BASIC_NAMES = ['Branches', 'Junctions', 'End-point Voxels',
+ 'Junction Voxels', 'Slab Voxels', 'Average branch length',
+ 'Triple Points', 'Quadruple Points', 'Maximum Branch Length']
+DETAIL_NAMES = ['Skeleton ID', 'Branch length', 'V1 x', 'V1 y', 'V1 z', 'V2 x',
+ 'V2 y', 'V2 z', 'Euclidean distance']
+OPTIONS = ['edm=Overwrite', 'iterations=1', 'count=1']
+
-def get_euclidean_distance( vertex1, vertex2 ):
- x1, y1, z1 = get_points( vertex1 )
- x2, y2, z2 = get_points( vertex2 )
- return math.sqrt( math.pow( ( x2 - x1 ), 2 ) +
- math.pow( ( y2 - y1 ), 2 ) +
- math.pow( ( z2 - z1 ), 2 ) )
+def get_euclidean_distance(vertex1, vertex2):
+ x1, y1, z1 = get_points(vertex1)
+ x2, y2, z2 = get_points(vertex2)
+ return math.sqrt(math.pow((x2 - x1), 2) + math.pow((y2 - y1), 2) + math.pow((z2 - z1), 2))
-def get_graph_length( graph ):
+
+def get_graph_length(graph):
length = 0
for edge in graph.getEdges():
length = length + edge.getLength()
return length
-def get_points( vertex ):
+
+def get_points(vertex):
# An array of Point, which has attributes x,y,z.
- point = vertex.getPoints()[ 0 ]
+ point = vertex.getPoints()[0]
return point.x, point.y, point.z
-
-def get_sorted_edge_lengths( graph ):
+
+
+def get_sorted_edge_lengths(graph):
# Return graph edges sorted from longest to shortest.
edges = graph.getEdges()
- edges = sorted( edges, key=lambda edge: edge.getLength(), reverse=True )
+ edges = sorted(edges, key=lambda edge: edge.getLength(), reverse=True)
return edges
-def get_sorted_graph_lengths( result ):
+
+def get_sorted_graph_lengths(result):
# Get the separate graphs (skeletons).
graphs = result.getGraph()
# Sort graphs from longest to shortest.
- graphs = sorted( graphs, key=lambda g: get_graph_length( g ), reverse=True )
+ graphs = sorted(graphs, key=lambda g: get_graph_length(g), reverse=True)
return graphs
-def save( result, output, show_detailed_info, calculate_largest_shortest_path, sep='\t' ):
- num_trees = int( result.getNumOfTrees() )
- outf = open( output, 'wb' )
- outf.write( '# %s\n' % sep.join( BASIC_NAMES ) )
- for index in range( num_trees ):
- outf.write( '%d%s' % ( result.getBranches()[ index ], sep ) )
- outf.write( '%d%s' % ( result.getJunctions()[ index ], sep ) )
- outf.write( '%d%s' % ( result.getEndPoints()[ index ], sep ) )
- outf.write( '%d%s' % ( result.getJunctionVoxels()[ index ], sep ) )
- outf.write( '%d%s' % ( result.getSlabs()[ index ], sep ) )
- outf.write( '%.3f%s' % ( result.getAverageBranchLength()[ index ], sep ) )
- outf.write( '%d%s' % ( result.getTriples()[ index ], sep ) )
- outf.write( '%d%s' % ( result.getQuadruples()[ index ], sep ) )
- outf.write( '%.3f' % result.getMaximumBranchLength()[ index ] )
+
+def save(result, output, show_detailed_info, calculate_largest_shortest_path, sep='\t'):
+ num_trees = int(result.getNumOfTrees())
+ outf = open(output, 'wb')
+ outf.write('# %s\n' % sep.join(BASIC_NAMES))
+ for index in range(num_trees):
+ outf.write('%d%s' % (result.getBranches()[index], sep))
+ outf.write('%d%s' % (result.getJunctions()[index], sep))
+ outf.write('%d%s' % (result.getEndPoints()[index], sep))
+ outf.write('%d%s' % (result.getJunctionVoxels()[index], sep))
+ outf.write('%d%s' % (result.getSlabs()[index], sep))
+ outf.write('%.3f%s' % (result.getAverageBranchLength()[index], sep))
+ outf.write('%d%s' % (result.getTriples()[index], sep))
+ outf.write('%d%s' % (result.getQuadruples()[index], sep))
+ outf.write('%.3f' % result.getMaximumBranchLength()[index])
if calculate_largest_shortest_path:
- outf.write( '%s%.3f%s' % ( sep, result.shortestPathList.get( index ), sep ) )
- outf.write( '%d%s' % ( result.spStartPosition[ index ][ 0 ], sep ) )
- outf.write( '%d%s' % ( result.spStartPosition[ index ][ 1 ], sep ) )
- outf.write( '%d\n' % result.spStartPosition[ index ][ 2 ] )
+ outf.write('%s%.3f%s' % (sep, result.shortestPathList.get(index), sep))
+ outf.write('%d%s' % (result.spStartPosition[index][0], sep))
+ outf.write('%d%s' % (result.spStartPosition[index][1], sep))
+ outf.write('%d\n' % result.spStartPosition[index][2])
else:
- outf.write( '\n' )
+ outf.write('\n')
if show_detailed_info:
- outf.write( '# %s\n' % sep.join( DETAIL_NAMES ) )
+ outf.write('# %s\n' % sep.join(DETAIL_NAMES))
# The following index is a placeholder for the skeleton ID.
# The terms "graph" and "skeleton" refer to the same thing.
# Also, the SkeletonResult.java code states that the
# private Graph[] graph object is an array of graphs (one
# per tree).
- for index, graph in enumerate( get_sorted_graph_lengths( result ) ):
- for edge in get_sorted_edge_lengths( graph ):
+ for index, graph in enumerate(get_sorted_graph_lengths(result)):
+ for edge in get_sorted_edge_lengths(graph):
vertex1 = edge.getV1()
- x1, y1, z1 = get_points( vertex1 )
+ x1, y1, z1 = get_points(vertex1)
vertex2 = edge.getV2()
- x2, y2, z2 = get_points( vertex2 )
- outf.write( '%d%s' % ( index+1, sep ) )
- outf.write( '%.3f%s' % ( edge.getLength(), sep ) )
- outf.write( '%d%s' % ( x1, sep ) )
- outf.write( '%d%s' % ( y1, sep ) )
- outf.write( '%d%s' % ( z1, sep ) )
- outf.write( '%d%s' % ( x2, sep ) )
- outf.write( '%d%s' % ( y2, sep ) )
- outf.write( '%d%s' % ( z2, sep ) )
- outf.write( '%.3f' % get_euclidean_distance( vertex1, vertex2 ) )
+ x2, y2, z2 = get_points(vertex2)
+ outf.write('%d%s' % (index + 1, sep))
+ outf.write('%.3f%s' % (edge.getLength(), sep))
+ outf.write('%d%s' % (x1, sep))
+ outf.write('%d%s' % (y1, sep))
+ outf.write('%d%s' % (z1, sep))
+ outf.write('%d%s' % (x2, sep))
+ outf.write('%d%s' % (y2, sep))
+ outf.write('%d%s' % (z2, sep))
+ outf.write('%.3f' % get_euclidean_distance(vertex1, vertex2))
if calculate_largest_shortest_path:
# Keep number of separated items the same for each line.
- outf.write( '%s %s' % ( sep, sep ) )
- outf.write( ' %s' % sep )
- outf.write( ' %s' % sep )
- outf.write( ' \n' )
+ outf.write('%s %s' % (sep, sep))
+ outf.write(' %s' % sep)
+ outf.write(' %s' % sep)
+ outf.write(' \n')
else:
- outf.write( '\n' )
+ outf.write('\n')
outf.close()
+
# Fiji Jython interpreter implements Python 2.5 which does not
# provide support for argparse.
-error_log = sys.argv[ -8 ]
-input = sys.argv[ -7 ]
-black_background = jython_utils.asbool( sys.argv[ -6 ] )
-prune_cycle_method = sys.argv[ -5 ]
-prune_ends = jython_utils.asbool( sys.argv[ -4 ] )
-calculate_largest_shortest_path = jython_utils.asbool( sys.argv[ -3 ] )
+error_log = sys.argv[-8]
+input = sys.argv[-7]
+black_background = sys.argv[-6] == "yes"
+prune_cycle_method = sys.argv[-5]
+prune_ends = sys.argv[-4] == "yes"
+calculate_largest_shortest_path = sys.argv[-3] == "yes"
if calculate_largest_shortest_path:
- BASIC_NAMES.extend( [ 'Longest Shortest Path', 'spx', 'spy', 'spz' ] )
- DETAIL_NAMES.extend( [ ' ', ' ', ' ', ' ' ] )
-show_detailed_info = jython_utils.asbool( sys.argv[ -2 ] )
-output = sys.argv[ -1 ]
+ BASIC_NAMES.extend(['Longest Shortest Path', 'spx', 'spy', 'spz'])
+ DETAIL_NAMES.extend([' ', ' ', ' ', ' '])
+show_detailed_info = sys.argv[-2] == "yes"
+output = 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_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():
- IJ.run( input_image_plus_copy, "Make Binary", "" )
+# Convert image to binary if necessary.
+if not image_processor_copy.isBinary():
+ IJ.run(input_image_plus_copy, "Make Binary", "")
- # Run AnalyzeSkeleton
- analyze_skeleton = AnalyzeSkeleton_()
- analyze_skeleton.setup( "", input_image_plus_copy )
- if prune_cycle_method == 'none':
- prune_index = analyze_skeleton.NONE
- elif prune_cycle_method == 'shortest_branch':
- prune_index = analyze_skeleton.SHORTEST_BRANCH
- elif prune_cycle_method == 'lowest_intensity_voxel':
- prune_index = analyze_skeleton.LOWEST_INTENSITY_VOXEL
- elif prune_cycle_method == 'lowest_intensity_branch':
- prune_index = analyze_skeleton.LOWEST_INTENSITY_BRANCH
- result = analyze_skeleton.run( prune_index,
- prune_ends,
- calculate_largest_shortest_path,
- input_image_plus_copy,
- True,
- True )
- # Save the results.
- save( result, output, show_detailed_info, calculate_largest_shortest_path )
-except Exception, e:
- jython_utils.handle_error( error_log, str( e ) )
+# Run AnalyzeSkeleton
+analyze_skeleton = AnalyzeSkeleton_()
+analyze_skeleton.setup("", input_image_plus_copy)
+if prune_cycle_method == 'none':
+ prune_index = analyze_skeleton.NONE
+elif prune_cycle_method == 'shortest_branch':
+ prune_index = analyze_skeleton.SHORTEST_BRANCH
+elif prune_cycle_method == 'lowest_intensity_voxel':
+ prune_index = analyze_skeleton.LOWEST_INTENSITY_VOXEL
+elif prune_cycle_method == 'lowest_intensity_branch':
+ prune_index = analyze_skeleton.LOWEST_INTENSITY_BRANCH
+result = analyze_skeleton.run(prune_index, prune_ends, calculate_largest_shortest_path, input_image_plus_copy, True, True)
+# Save the results.
+save(result, output, show_detailed_info, calculate_largest_shortest_path)
diff -r 1bf7e70e67f9 -r 8d357579e407 imagej2_base_utils.py
--- a/imagej2_base_utils.py Tue Sep 17 16:56:02 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)
diff -r 1bf7e70e67f9 -r 8d357579e407 imagej2_binary_to_edm.py
--- a/imagej2_binary_to_edm.py Tue Sep 17 16:56:02 2019 -0400
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -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 )
diff -r 1bf7e70e67f9 -r 8d357579e407 imagej2_binary_to_edm_jython_script.py
--- a/imagej2_binary_to_edm_jython_script.py Tue Sep 17 16:56:02 2019 -0400
+++ b/imagej2_binary_to_edm_jython_script.py Mon Sep 28 16:56:53 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)
diff -r 1bf7e70e67f9 -r 8d357579e407 imagej2_bunwarpj_adapt_transform.py
--- a/imagej2_bunwarpj_adapt_transform.py Tue Sep 17 16:56:02 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( '--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 )
diff -r 1bf7e70e67f9 -r 8d357579e407 imagej2_bunwarpj_align.py
--- a/imagej2_bunwarpj_align.py Tue Sep 17 16:56:02 2019 -0400
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,178 +0,0 @@
-#!/usr/bin/env python
-import argparse
-import os
-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( '--source_mask', dest='source_mask', default=None, help='Source mask' )
-parser.add_argument( '--source_mask_format', dest='source_mask_format', default=None, help='Source mask 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_mask', dest='target_mask', default=None, help='Target mask' )
-parser.add_argument( '--target_mask_format', dest='target_mask_format', default=None, help='Target mask image format' )
-parser.add_argument( '--min_scale_def', dest='min_scale_def', type=int, help='Initial deformation' )
-parser.add_argument( '--max_scale_def', dest='max_scale_def', type=int, help='Final deformation' )
-parser.add_argument( '--max_subsamp_fact', dest='max_subsamp_fact', type=int, help='Image sub-sample factor' )
-parser.add_argument( '--divergence_weight', dest='divergence_weight', type=float, help='Divergence weight' )
-parser.add_argument( '--curl_weight', dest='curl_weight', type=float, help='Curl weight' )
-parser.add_argument( '--image_weight', dest='image_weight', type=float, help='Image weight' )
-parser.add_argument( '--consistency_weight', dest='consistency_weight', type=float, help='Consistency weight' )
-parser.add_argument( '--landmarks_weight', dest='landmarks_weight', type=float, help='Landmarks weight' )
-parser.add_argument( '--landmarks_file', dest='landmarks_file', default=None, help='Landmarks file' )
-parser.add_argument( '--source_affine_file', dest='source_affine_file', default=None, help='Initial source affine matrix transformation' )
-parser.add_argument( '--target_affine_file', dest='target_affine_file', default=None, help='Initial target affine matrix transformation' )
-parser.add_argument( '--mono', dest='mono', default=False, help='Unidirectional registration (source to target)' )
-parser.add_argument( '--source_trans_out', dest='source_trans_out', default=None, help='Direct source transformation matrix' )
-parser.add_argument( '--target_trans_out', dest='target_trans_out', default=None, help='Inverse target transformation matrix' )
-parser.add_argument( '--source_out', help='Output source image' )
-parser.add_argument( '--source_out_datatype', help='Output registered source image format' )
-parser.add_argument( '--target_out', default=None, help='Output target image' )
-parser.add_argument( '--target_out_datatype', default=None, help='Output registered target image format' )
-parser.add_argument( '--jython_script', dest='jython_script', help='Path to the Jython script' )
-
-args = parser.parse_args()
-
-if args.source_trans_out is not None and args.target_trans_out is not None:
- save_transformation = True
-else:
- save_transformation = False
-
-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 )
-if not args.mono:
- tmp_target_out_tiff_path = imagej2_base_utils.get_temporary_image_path( tmp_dir, 'tiff' )
- tmp_target_out_path = imagej2_base_utils.get_temporary_image_path( tmp_dir, args.target_out_datatype )
-if args.source_mask is not None and args.target_mask is not None:
- tmp_source_mask_path = imagej2_base_utils.get_input_image_path( tmp_dir, args.source_mask, args.source_mask_format )
- tmp_target_mask_path = imagej2_base_utils.get_input_image_path( tmp_dir, args.target_mask, args.target_mask_format )
-if save_transformation:
- # bUnwarpJ automatically names the transformation files based on the names
- # of the source and target image file names. We've defined symlinks to
- # temporary files with valid image extensions since ImageJ does not handle
- # the Galaxy "dataset.dat" file extensions.
- source_file_name = imagej2_base_utils.get_file_name_without_extension( tmp_source_out_tiff_path )
- tmp_source_out_transf_path = os.path.join( tmp_dir, '%s_transf.txt' % source_file_name )
- target_file_name = imagej2_base_utils.get_file_name_without_extension( tmp_target_out_tiff_path )
- tmp_target_out_transf_path = os.path.join( tmp_dir, '%s_transf.txt' % target_file_name )
-
-# 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 align the two images.
-cmd = imagej2_base_utils.get_base_cmd_bunwarpj( None )
-if cmd is None:
- imagej2_base_utils.stop_err( "bUnwarpJ not found!" )
-cmd += ' -align'
-# Target is sent before source.
-cmd += ' %s' % target_image_path
-if args.target_mask is None:
- target_mask_str = ' NULL'
-else:
- target_mask_str = ' %s' % tmp_target_mask_path
-cmd += target_mask_str
-cmd += ' %s' % source_image_path
-if args.source_mask is None:
- source_mask_str = ' NULL'
-else:
- source_mask_str = ' %s' % tmp_source_mask_path
-cmd += source_mask_str
-cmd += ' %d' % args.min_scale_def
-cmd += ' %d' % args.max_scale_def
-cmd += ' %d' % args.max_subsamp_fact
-cmd += ' %.1f' % args.divergence_weight
-cmd += ' %.1f' % args.curl_weight
-cmd += ' %.1f' % args.image_weight
-cmd += ' %.1f' % args.consistency_weight
-# Source is produced before target.
-cmd += ' %s' % tmp_source_out_tiff_path
-if not args.mono:
- cmd += ' %s' % tmp_target_out_tiff_path
-if args.landmarks_file is not None:
- # We have to create a temporary file with a .txt extension here so that
- # bUnwarpJ will not ignore the Galaxy "dataset.dat" file.
- tmp_landmarks_file_path = imagej2_base_utils.get_input_image_path( tmp_dir,
- args.landmarks_file,
- 'txt' )
- cmd += ' -landmarks'
- cmd += ' %.1f' % args.landmarks_weight
- cmd += ' %s' % tmp_landmarks_file_path
-if args.source_affine_file is not None and args.target_affine_file is not None:
- # Target is sent before source.
- cmd += ' -affine'
- cmd += ' %s' % args.target_affine_file
- cmd += ' %s' % args.source_affine_file
-if args.mono:
- cmd += ' -mono'
-if save_transformation:
- cmd += ' -save_transformation'
-
-# Align the two images 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 )
-
-# bUnwarpJ 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. Galaxy supports only single-layered images, so we'll convert the images so they
-# can be viewed in Galaxy.
-
-# 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 handle the multi-slice tiff images.
-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!" )
-if args.mono:
- # bUnwarpJ will produce only a registered source image.
- cmd += ' %s %s %s %s' % ( tmp_source_out_tiff_path,
- args.source_out_datatype,
- tmp_source_out_path,
- args.mono )
-else:
- # bUnwarpJ will produce registered source and target images.
- cmd += ' %s %s %s %s %s %s %s' % ( tmp_source_out_tiff_path,
- args.source_out_datatype,
- tmp_source_out_path,
- tmp_target_out_tiff_path,
- args.target_out_datatype,
- tmp_target_out_path,
- args.mono )
-
-# Merge the multi-slice tiff layers into an image that can be viewed in Galaxy.
-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 output dataset.
-shutil.move( tmp_source_out_path, args.source_out )
-if not args.mono:
- # Move the Registered Target Image to the output dataset.
- shutil.move( tmp_target_out_path, args.target_out )
-
-# If requested, save matrix transformations as additional datasets.
-if save_transformation:
- shutil.move( tmp_source_out_transf_path, args.source_trans_out )
- if not args.mono:
- shutil.move( tmp_target_out_transf_path, args.target_trans_out )
-
-imagej2_base_utils.cleanup_before_exit( tmp_dir )
diff -r 1bf7e70e67f9 -r 8d357579e407 imagej2_bunwarpj_align_jython_script.py
--- a/imagej2_bunwarpj_align_jython_script.py Tue Sep 17 16:56:02 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 )
diff -r 1bf7e70e67f9 -r 8d357579e407 imagej2_bunwarpj_compare_elastic.py
--- a/imagej2_bunwarpj_compare_elastic.py Tue Sep 17 16:56:02 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 )
diff -r 1bf7e70e67f9 -r 8d357579e407 imagej2_bunwarpj_compare_elastic_raw.py
--- a/imagej2_bunwarpj_compare_elastic_raw.py Tue Sep 17 16:56:02 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 )
diff -r 1bf7e70e67f9 -r 8d357579e407 imagej2_bunwarpj_compare_raw.py
--- a/imagej2_bunwarpj_compare_raw.py Tue Sep 17 16:56:02 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 )
diff -r 1bf7e70e67f9 -r 8d357579e407 imagej2_bunwarpj_compose_elastic.py
--- a/imagej2_bunwarpj_compose_elastic.py Tue Sep 17 16:56:02 2019 -0400
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -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 )
diff -r 1bf7e70e67f9 -r 8d357579e407 imagej2_bunwarpj_compose_raw.py
--- a/imagej2_bunwarpj_compose_raw.py Tue Sep 17 16:56:02 2019 -0400
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -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 )
diff -r 1bf7e70e67f9 -r 8d357579e407 imagej2_bunwarpj_compose_raw_elastic.py
--- a/imagej2_bunwarpj_compose_raw_elastic.py Tue Sep 17 16:56:02 2019 -0400
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -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 )
diff -r 1bf7e70e67f9 -r 8d357579e407 imagej2_bunwarpj_compose_raw_elastic.xml
--- a/imagej2_bunwarpj_compose_raw_elastic.xml Tue Sep 17 16:56:02 2019 -0400
+++ b/imagej2_bunwarpj_compose_raw_elastic.xml Mon Sep 28 16:56:53 2020 +0000
@@ -1,38 +1,44 @@
-
into a raw transformation with bUnwarpJ
imagej2_macros.xml
-
-
-
-
+
+ '$output_log';
+if [[ $? -ne 0 ]]; then
+ cat '$output_log' >&2;
+fi
+]]>
-
-
+
+
-
+
-
-
-
-
-
+
+
+
+
@@ -44,5 +50,5 @@
]]>
-
+
diff -r 1bf7e70e67f9 -r 8d357579e407 imagej2_bunwarpj_convert_to_raw.py
--- a/imagej2_bunwarpj_convert_to_raw.py Tue Sep 17 16:56:02 2019 -0400
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -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 )
diff -r 1bf7e70e67f9 -r 8d357579e407 imagej2_bunwarpj_elastic_transform.py
--- a/imagej2_bunwarpj_elastic_transform.py Tue Sep 17 16:56:02 2019 -0400
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -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 )
diff -r 1bf7e70e67f9 -r 8d357579e407 imagej2_bunwarpj_elastic_transform_jython_script.py
--- a/imagej2_bunwarpj_elastic_transform_jython_script.py Tue Sep 17 16:56:02 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 )
diff -r 1bf7e70e67f9 -r 8d357579e407 imagej2_bunwarpj_raw_transform.py
--- a/imagej2_bunwarpj_raw_transform.py Tue Sep 17 16:56:02 2019 -0400
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -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 )
diff -r 1bf7e70e67f9 -r 8d357579e407 imagej2_bunwarpj_raw_transform_jython_script.py
--- a/imagej2_bunwarpj_raw_transform_jython_script.py Tue Sep 17 16:56:02 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 )
diff -r 1bf7e70e67f9 -r 8d357579e407 imagej2_create_image.py
--- a/imagej2_create_image.py Tue Sep 17 16:56:02 2019 -0400
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -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 )
diff -r 1bf7e70e67f9 -r 8d357579e407 imagej2_create_image_jython_script.py
--- a/imagej2_create_image_jython_script.py Tue Sep 17 16:56:02 2019 -0400
+++ b/imagej2_create_image_jython_script.py Mon Sep 28 16:56:53 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)
diff -r 1bf7e70e67f9 -r 8d357579e407 imagej2_enhance_contrast.py
--- a/imagej2_enhance_contrast.py Tue Sep 17 16:56:02 2019 -0400
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -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 )
diff -r 1bf7e70e67f9 -r 8d357579e407 imagej2_enhance_contrast_jython_script.py
--- a/imagej2_enhance_contrast_jython_script.py Tue Sep 17 16:56:02 2019 -0400
+++ b/imagej2_enhance_contrast_jython_script.py Mon Sep 28 16:56:53 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)
diff -r 1bf7e70e67f9 -r 8d357579e407 imagej2_find_edges.py
--- a/imagej2_find_edges.py Tue Sep 17 16:56:02 2019 -0400
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -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 )
diff -r 1bf7e70e67f9 -r 8d357579e407 imagej2_find_edges_jython_script.py
--- a/imagej2_find_edges_jython_script.py Tue Sep 17 16:56:02 2019 -0400
+++ b/imagej2_find_edges_jython_script.py Mon Sep 28 16:56:53 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)
diff -r 1bf7e70e67f9 -r 8d357579e407 imagej2_find_maxima.py
--- a/imagej2_find_maxima.py Tue Sep 17 16:56:02 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( '--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 )
diff -r 1bf7e70e67f9 -r 8d357579e407 imagej2_find_maxima_jython_script.py
--- a/imagej2_find_maxima_jython_script.py Tue Sep 17 16:56:02 2019 -0400
+++ b/imagej2_find_maxima_jython_script.py Mon Sep 28 16:56:53 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)
diff -r 1bf7e70e67f9 -r 8d357579e407 imagej2_macros.xml
--- a/imagej2_macros.xml Tue Sep 17 16:56:02 2019 -0400
+++ b/imagej2_macros.xml Mon Sep 28 16:56:53 2020 +0000
@@ -1,9 +1,9 @@
-
3.0
fiji
+ grep
@@ -16,7 +16,7 @@
-
+
@@ -38,20 +38,45 @@
-
+
-
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
--iterations $iterations
--count $count
diff -r 1bf7e70e67f9 -r 8d357579e407 imagej2_make_binary.py
--- a/imagej2_make_binary.py Tue Sep 17 16:56:02 2019 -0400
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -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 )
diff -r 1bf7e70e67f9 -r 8d357579e407 imagej2_make_binary_jython_script.py
--- a/imagej2_make_binary_jython_script.py Tue Sep 17 16:56:02 2019 -0400
+++ b/imagej2_make_binary_jython_script.py Mon Sep 28 16:56:53 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)
diff -r 1bf7e70e67f9 -r 8d357579e407 imagej2_math.py
--- a/imagej2_math.py Tue Sep 17 16:56:02 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 )
diff -r 1bf7e70e67f9 -r 8d357579e407 imagej2_math_jython_script.py
--- a/imagej2_math_jython_script.py Tue Sep 17 16:56:02 2019 -0400
+++ b/imagej2_math_jython_script.py Mon Sep 28 16:56:53 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)
diff -r 1bf7e70e67f9 -r 8d357579e407 imagej2_noise.py
--- a/imagej2_noise.py Tue Sep 17 16:56:02 2019 -0400
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -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 )
diff -r 1bf7e70e67f9 -r 8d357579e407 imagej2_noise_jython_script.py
--- a/imagej2_noise_jython_script.py Tue Sep 17 16:56:02 2019 -0400
+++ b/imagej2_noise_jython_script.py Mon Sep 28 16:56:53 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)
diff -r 1bf7e70e67f9 -r 8d357579e407 imagej2_shadows.py
--- a/imagej2_shadows.py Tue Sep 17 16:56:02 2019 -0400
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -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 )
diff -r 1bf7e70e67f9 -r 8d357579e407 imagej2_shadows_jython_script.py
--- a/imagej2_shadows_jython_script.py Tue Sep 17 16:56:02 2019 -0400
+++ b/imagej2_shadows_jython_script.py Mon Sep 28 16:56:53 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)
diff -r 1bf7e70e67f9 -r 8d357579e407 imagej2_sharpen.py
--- a/imagej2_sharpen.py Tue Sep 17 16:56:02 2019 -0400
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -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 )
diff -r 1bf7e70e67f9 -r 8d357579e407 imagej2_sharpen_jython_script.py
--- a/imagej2_sharpen_jython_script.py Tue Sep 17 16:56:02 2019 -0400
+++ b/imagej2_sharpen_jython_script.py Mon Sep 28 16:56:53 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)
diff -r 1bf7e70e67f9 -r 8d357579e407 imagej2_skeletonize3d.py
--- a/imagej2_skeletonize3d.py Tue Sep 17 16:56:02 2019 -0400
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -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 )
diff -r 1bf7e70e67f9 -r 8d357579e407 imagej2_skeletonize3d_jython_script.py
--- a/imagej2_skeletonize3d_jython_script.py Tue Sep 17 16:56:02 2019 -0400
+++ b/imagej2_skeletonize3d_jython_script.py Mon Sep 28 16:56:53 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)
diff -r 1bf7e70e67f9 -r 8d357579e407 imagej2_smooth.py
--- a/imagej2_smooth.py Tue Sep 17 16:56:02 2019 -0400
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -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 )
diff -r 1bf7e70e67f9 -r 8d357579e407 imagej2_smooth_jython_script.py
--- a/imagej2_smooth_jython_script.py Tue Sep 17 16:56:02 2019 -0400
+++ b/imagej2_smooth_jython_script.py Mon Sep 28 16:56:53 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)
diff -r 1bf7e70e67f9 -r 8d357579e407 imagej2_watershed_binary.py
--- a/imagej2_watershed_binary.py Tue Sep 17 16:56:02 2019 -0400
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -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 )
diff -r 1bf7e70e67f9 -r 8d357579e407 imagej2_watershed_binary_jython_script.py
--- a/imagej2_watershed_binary_jython_script.py Tue Sep 17 16:56:02 2019 -0400
+++ b/imagej2_watershed_binary_jython_script.py Mon Sep 28 16:56:53 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)
diff -r 1bf7e70e67f9 -r 8d357579e407 jython_utils.py
--- a/jython_utils.py Tue Sep 17 16:56:02 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()
diff -r 1bf7e70e67f9 -r 8d357579e407 test-data/analyze_particles_masks.gif
Binary file test-data/analyze_particles_masks.gif has changed
diff -r 1bf7e70e67f9 -r 8d357579e407 test-data/analyze_particles_nothing.tabular
--- a/test-data/analyze_particles_nothing.tabular Tue Sep 17 16:56:02 2019 -0400
+++ b/test-data/analyze_particles_nothing.tabular Mon Sep 28 16:56:53 2020 +0000
@@ -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
diff -r 1bf7e70e67f9 -r 8d357579e407 test-data/analyze_particles_outlines.gif
Binary file test-data/analyze_particles_outlines.gif has changed
diff -r 1bf7e70e67f9 -r 8d357579e407 test-data/basic.tabular
--- a/test-data/basic.tabular Tue Sep 17 16:56:02 2019 -0400
+++ b/test-data/basic.tabular Mon Sep 28 16:56:53 2020 +0000
@@ -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
diff -r 1bf7e70e67f9 -r 8d357579e407 test-data/blobs_black_edm.gif
Binary file test-data/blobs_black_edm.gif has changed
diff -r 1bf7e70e67f9 -r 8d357579e407 test-data/blobs_edm.gif
Binary file test-data/blobs_edm.gif has changed
diff -r 1bf7e70e67f9 -r 8d357579e407 test-data/blobs_equalize.gif
Binary file test-data/blobs_equalize.gif has changed
diff -r 1bf7e70e67f9 -r 8d357579e407 test-data/blobs_find_edges.gif
Binary file test-data/blobs_find_edges.gif has changed
diff -r 1bf7e70e67f9 -r 8d357579e407 test-data/blobs_log.gif
Binary file test-data/blobs_log.gif has changed
diff -r 1bf7e70e67f9 -r 8d357579e407 test-data/blobs_min.gif
Binary file test-data/blobs_min.gif has changed
diff -r 1bf7e70e67f9 -r 8d357579e407 test-data/blobs_multiply.gif
Binary file test-data/blobs_multiply.gif has changed
diff -r 1bf7e70e67f9 -r 8d357579e407 test-data/blobs_normalize.gif
Binary file test-data/blobs_normalize.gif has changed
diff -r 1bf7e70e67f9 -r 8d357579e407 test-data/blobs_northwest.gif
Binary file test-data/blobs_northwest.gif has changed
diff -r 1bf7e70e67f9 -r 8d357579e407 test-data/blobs_saturate.gif
Binary file test-data/blobs_saturate.gif has changed
diff -r 1bf7e70e67f9 -r 8d357579e407 test-data/blobs_segmented.gif
Binary file test-data/blobs_segmented.gif has changed
diff -r 1bf7e70e67f9 -r 8d357579e407 test-data/blobs_single_points.gif
Binary file test-data/blobs_single_points.gif has changed
diff -r 1bf7e70e67f9 -r 8d357579e407 test-data/blobs_square.gif
Binary file test-data/blobs_square.gif has changed
diff -r 1bf7e70e67f9 -r 8d357579e407 test-data/blobs_tolerance.gif
Binary file test-data/blobs_tolerance.gif has changed
diff -r 1bf7e70e67f9 -r 8d357579e407 test-data/blobs_watershed_binary.gif
Binary file test-data/blobs_watershed_binary.gif has changed
diff -r 1bf7e70e67f9 -r 8d357579e407 test-data/elastic_trans_registered_source1.png
Binary file test-data/elastic_trans_registered_source1.png has changed
diff -r 1bf7e70e67f9 -r 8d357579e407 test-data/largest_shortest_path_basic.tabular
--- a/test-data/largest_shortest_path_basic.tabular Tue Sep 17 16:56:02 2019 -0400
+++ b/test-data/largest_shortest_path_basic.tabular Mon Sep 28 16:56:53 2020 +0000
@@ -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
diff -r 1bf7e70e67f9 -r 8d357579e407 test-data/raw_trans_registered_source1.png
Binary file test-data/raw_trans_registered_source1.png has changed
diff -r 1bf7e70e67f9 -r 8d357579e407 test-data/registered_source1.png
Binary file test-data/registered_source1.png has changed
diff -r 1bf7e70e67f9 -r 8d357579e407 test-data/registered_source2.png
Binary file test-data/registered_source2.png has changed
diff -r 1bf7e70e67f9 -r 8d357579e407 test-data/registered_target1.png
Binary file test-data/registered_target1.png has changed
diff -r 1bf7e70e67f9 -r 8d357579e407 test-data/registered_target2.png
Binary file test-data/registered_target2.png has changed
diff -r 1bf7e70e67f9 -r 8d357579e407 test-data/skeletonized_blobs.gif
Binary file test-data/skeletonized_blobs.gif has changed
diff -r 1bf7e70e67f9 -r 8d357579e407 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:56:53 2020 +0000
@@ -0,0 +1,5 @@
+Intervals=4
+
+X Coeffs -----------------------------------
+
+Y Coeffs -----------------------------------
diff -r 1bf7e70e67f9 -r 8d357579e407 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:56:53 2020 +0000
@@ -0,0 +1,5 @@
+Intervals=4
+
+X Coeffs -----------------------------------
+
+Y Coeffs -----------------------------------