# HG changeset patch # User imgteam # Date 1727279910 0 # Node ID 4409f9eb94332d965828bb50905f83c29f2ed738 # Parent 6a07f71806bb8847ed892f3ac44bbcfd930c43ca planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56 diff -r 6a07f71806bb -r 4409f9eb9433 imagej2_adjust_threshold_binary_jython_script.py --- a/imagej2_adjust_threshold_binary_jython_script.py Sun Nov 05 14:19:21 2023 +0000 +++ b/imagej2_adjust_threshold_binary_jython_script.py Wed Sep 25 15:58:30 2024 +0000 @@ -1,18 +1,15 @@ import sys -from ij import IJ +from ij import IJ, Prefs # Fiji Jython interpreter implements Python 2.5 which does not # provide support for argparse. -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 = sys.argv[-3] == "yes" +input_file = sys.argv[-8] +threshold_min = float(sys.argv[-7]) +threshold_max = float(sys.argv[-6]) +method = sys.argv[-5] +display = sys.argv[-4] +black_background = sys.argv[-3] == "yes" output_filename = sys.argv[-2] output_datatype = sys.argv[-1] @@ -21,22 +18,34 @@ # Create a copy of the image. input_image_plus_copy = input_image_plus.duplicate() -image_processor_copy = input_image_plus_copy.getProcessor() + +bit_depth = input_image_plus_copy.getBitDepth() + +if black_background: + Prefs.blackBackground = True +else: + Prefs.blackBackground = False -# 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 method != "Manual": + # Set the options. + if black_background: + method_str = "%s dark" % method + suffix = "black" + else: + method_str = method + suffix = "" + threshold_min = 1 + # Set threshold_max based on image bit-depth + # For 8-bit images, use 255; for 16-bit images, use 65535 + if bit_depth == 8: + threshold_max = 255 # Default for 8-bit images + elif bit_depth == 16: + threshold_max = 65535 # Default for 16-bit images + else: + threshold_max = float('inf') # General fallback if bit depth is unknown + + IJ.setAutoThreshold(input_image_plus_copy, method_str) + IJ.run(input_image_plus_copy, "Convert to Mask", "calculate %s" % suffix) if display == "red": display_mode = "Red" elif display == "bw": @@ -44,7 +53,5 @@ 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 6a07f71806bb -r 4409f9eb9433 imagej2_analyze_particles_binary_jython_script.py --- a/imagej2_analyze_particles_binary_jython_script.py Sun Nov 05 14:19:21 2023 +0000 +++ b/imagej2_analyze_particles_binary_jython_script.py Wed Sep 25 15:58:30 2024 +0000 @@ -1,27 +1,32 @@ import sys -from ij import IJ +from ij import IJ, Prefs 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_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" +roi_coordinate_file = sys.argv[-13] +input_file = sys.argv[-12] +black_background = sys.argv[-11] == "yes" +size = sys.argv[-10] +circularity_min = float(sys.argv[-9]) +circularity_max = float(sys.argv[-8]) +show = sys.argv[-7] +display_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] + +if black_background: + Prefs.blackBackground = True +else: + Prefs.blackBackground = False + # Open the input image file. input_image_plus = IJ.openImage(input_file) @@ -42,9 +47,32 @@ IJ.run(input_image_plus_copy, "Make Binary", "") # Set the options. -options = ["size=%s" % size] +options = ["size=%s" % size, "stack"] circularity_str = "%.3f-%.3f" % (circularity_min, circularity_max) options.append("circularity=%s" % circularity_str) +if exclude_edges: + options.append("exclude") +if include_holes: + options.append("include") + +# If you need the coordinates of ROIs we compute it twice +if len(roi_coordinate_file) > 0: + options2 = list(options) + options2.append("show=Overlay") + IJ.run(input_image_plus_copy, "Analyze Particles...", " ".join(options2)) + ov = input_image_plus_copy.getOverlay() + with open(roi_coordinate_file, 'w') as fo: + fo.write("shape\tpoints\tlabel\tt\tz\n") + for i, roi in enumerate(ov): + if roi.getName() is None: + roi.name = "ROI_%d" % i + poly = roi.getPolygon() + x_values = poly.xpoints + y_values = poly.ypoints + points_coo = ",".join(["(%d,%d)" % (x, y) for x, y in zip(x_values, y_values)]) + fo.write("Polygon\t%s\t%s\t%d\t%d\n" % (points_coo, roi.getName(), roi.getTPosition(), roi.getZPosition())) + analyzer.resetCounter() + if show.find("_") >= 0: show_str = "[%s]" % show.replace("_", " ") else: @@ -52,12 +80,6 @@ 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") @@ -68,6 +90,6 @@ 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: +if len(results_path) > 0: results_table = analyzer.getResultsTable() results_table.saveAs(results_path) diff -r 6a07f71806bb -r 4409f9eb9433 imagej2_analyze_skeleton_jython_script.py --- a/imagej2_analyze_skeleton_jython_script.py Sun Nov 05 14:19:21 2023 +0000 +++ b/imagej2_analyze_skeleton_jython_script.py Wed Sep 25 15:58:30 2024 +0000 @@ -121,7 +121,6 @@ # 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 = sys.argv[-6] == "yes" prune_cycle_method = sys.argv[-5] diff -r 6a07f71806bb -r 4409f9eb9433 imagej2_binary_to_edm_jython_script.py --- a/imagej2_binary_to_edm_jython_script.py Sun Nov 05 14:19:21 2023 +0000 +++ b/imagej2_binary_to_edm_jython_script.py Wed Sep 25 15:58:30 2024 +0000 @@ -4,7 +4,6 @@ # Fiji Jython interpreter implements Python 2.5 which does not # provide support for argparse. -error_log = sys.argv[-8] input_file = sys.argv[-7] iterations = int(sys.argv[-6]) count = int(sys.argv[-5]) diff -r 6a07f71806bb -r 4409f9eb9433 imagej2_crop_jython_script.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/imagej2_crop_jython_script.py Wed Sep 25 15:58:30 2024 +0000 @@ -0,0 +1,55 @@ +import sys + +from ij import IJ +from ij.plugin import Duplicator + +# Fiji Jython interpreter implements Python 2.5 which does not +# provide support for argparse. +input_file = sys.argv[-13] +xleft = int(sys.argv[-12]) +width = int(sys.argv[-11]) +ytop = int(sys.argv[-10]) +height = int(sys.argv[-9]) +first_channel = int(sys.argv[-8]) +last_channel = int(sys.argv[-7]) +first_slice = int(sys.argv[-6]) +last_slice = int(sys.argv[-5]) +first_frame = int(sys.argv[-4]) +last_frame = int(sys.argv[-3]) +output_filename = sys.argv[-2] +output_datatype = sys.argv[-1] + +# Open the input image file. +input_image_plus = IJ.openImage(input_file) + +# Get image dimensions (width, height, nChannels, nSlices, nFrames) +image_dims = input_image_plus.getDimensions() + +# Create a copy of the image. +input_image_plus_copy = input_image_plus.duplicate() + +# Determine if crop in XY is needed: +if xleft != 0 or width != 0 or ytop != 0 or height != 0: + # Need to define a ROI + if width == 0: + width = image_dims[0] - xleft + if height == 0: + height = image_dims[1] - ytop + input_image_plus_copy.setRoi(xleft, ytop, width, height) + +# Replace 0's with default: +if last_channel == 0: + last_channel = image_dims[2] +if last_slice == 0: + last_slice = image_dims[3] +if last_frame == 0: + last_frame = image_dims[4] +print("Original dimensions:") +print(image_dims) +# This will also crop in XY is a ROI has been set +input_image_plus_copy = Duplicator().run(input_image_plus_copy, first_channel, last_channel, first_slice, last_slice, first_frame, last_frame) +print("Final dimensions:") +print(input_image_plus_copy.getDimensions()) + +# Save the ImagePlus object as a new image. +IJ.saveAs(input_image_plus_copy, output_datatype, output_filename) diff -r 6a07f71806bb -r 4409f9eb9433 imagej2_enhance_contrast_jython_script.py --- a/imagej2_enhance_contrast_jython_script.py Sun Nov 05 14:19:21 2023 +0000 +++ b/imagej2_enhance_contrast_jython_script.py Wed Sep 25 15:58:30 2024 +0000 @@ -4,7 +4,6 @@ # 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 = sys.argv[-5] == "yes" saturated_pixels = sys.argv[-4] diff -r 6a07f71806bb -r 4409f9eb9433 imagej2_filter_jython_script.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/imagej2_filter_jython_script.py Wed Sep 25 15:58:30 2024 +0000 @@ -0,0 +1,39 @@ +import sys + +from ij import IJ + +# Fiji Jython interpreter implements Python 2.5 which does not +# provide support for argparse. +input_file = sys.argv[-8] +image_datatype = sys.argv[-7] +filter = sys.argv[-6] +radius = sys.argv[-5] +mask = sys.argv[-4] +light_background = sys.argv[-3] +dont_substract = sys.argv[-2] +tmp_output_path = sys.argv[-1] + +# Open the input image file. +image_plus = IJ.openImage(input_file) +# Create an ImagePlus object for the image. +image_plus_copy = image_plus.duplicate() + +# Perform the analysis on the ImagePlus object. +try: + if filter == "gaussian_blur": + IJ.run(image_plus_copy, "Gaussian Blur...", "sigma=%s stack" % radius) + elif filter in ["median", "mean", "minimum", "maximum", "variance"]: + IJ.run(image_plus_copy, "%s..." % filter.title(), "radius=%s stack" % radius) + elif filter == "unsharp_mask": + IJ.run(image_plus_copy, "Unsharp Mask...", "radius=%s mask=%s stack" % (radius, mask)) + elif filter == "top_hat": + print("radius=%s %s %s" % (radius, light_background, dont_substract.replace('dont', "don't"))) + IJ.run(image_plus_copy, "Top Hat...", "radius=%s %s %s stack" % (radius, light_background, dont_substract.replace('dont', "don't"))) +except Exception as e: + # This is due to some operations like gaussian_blur which block the script + print(e) + exit(1) +# Save the ImagePlus object as a new image. +IJ.saveAs(image_plus_copy, image_datatype, tmp_output_path) +# This is due to some operations like gaussian_blur which block the script +exit(0) diff -r 6a07f71806bb -r 4409f9eb9433 imagej2_find_edges_jython_script.py --- a/imagej2_find_edges_jython_script.py Sun Nov 05 14:19:21 2023 +0000 +++ b/imagej2_find_edges_jython_script.py Wed Sep 25 15:58:30 2024 +0000 @@ -4,7 +4,6 @@ # 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] diff -r 6a07f71806bb -r 4409f9eb9433 imagej2_find_maxima.xml --- a/imagej2_find_maxima.xml Sun Nov 05 14:19:21 2023 +0000 +++ b/imagej2_find_maxima.xml Wed Sep 25 15:58:30 2024 +0000 @@ -1,4 +1,4 @@ - + with ImageJ2 imagej2_macros.xml @@ -13,9 +13,8 @@ '$error_log'; -if [[ $? -ne 0 ]]; then - cat '$error_log' >&2; -else - #if $list_or_count: - mv '$results' '$output'; - #else: - mv '$output_filename' '$output'; - #end if -fi +#if $list_or_count + && mv '$results' '$output'; +#else + && mv '$output_filename' '$output'; +#end if ]]> @@ -89,27 +81,28 @@ output_type != "List" and output_type != "Count" + - + - + - + - + - + - +