From d693f307b6a619e86f95c4e55cdd4a20e487228d Mon Sep 17 00:00:00 2001 From: Laurent Guerard <laurent.guerard@unibas.ch> Date: Tue, 14 Jan 2025 14:05:32 +0100 Subject: [PATCH] Improve speed by hiding the image during processing --- 2c_fibertyping.py | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) mode change 100755 => 100644 2c_fibertyping.py diff --git a/2c_fibertyping.py b/2c_fibertyping.py old mode 100755 new mode 100644 index ffc1520..cc43e62 --- a/2c_fibertyping.py +++ b/2c_fibertyping.py @@ -100,7 +100,7 @@ def open_image_with_BF(path_to_file): # Create an ImporterOptions object for configuring the import process options = ImporterOptions() # Set the color mode to grayscale - options.setColorMode(ImporterOptions.COLOR_MODE_GRAYSCALE) + options.setColorMode(ImporterOptions.COLOR_MODE_COMPOSITE ) # Enable autoscaling for the image options.setAutoscale(True) # Set the file path for the image to be opened @@ -231,12 +231,12 @@ def change_all_roi_color(rm, color): None """ # Select all ROIs in the RoiManager - rm.setSelectedIndexes(range(rm.getCount())) - + #rm.setSelectedIndexes(range(rm.getCount())) + rm.runCommand("Deselect") # Change the color of all ROIs to the desired color rm.runCommand("Set Color", color) - # Deselect all ROIs again to finalize changes - rm.runCommand("Deselect") + # # Deselect all ROIs again to finalize changes + # rm.runCommand("Deselect") def change_subset_roi_color(rm, selected_rois, color): @@ -252,6 +252,7 @@ def change_subset_roi_color(rm, selected_rois, color): color : str The desired color, e.g., "green", "red", "yellow", "magenta", etc. """ + # Deselect all currently selected ROIs in the RoiManager rm.runCommand("Deselect") # Select the specified ROIs by their indices @@ -464,6 +465,7 @@ setup_defined_ij(rm, rt) # open image using Bio-Formats path_to_image = fix_ij_dirs(path_to_image) raw = open_image_with_BF(path_to_image) +raw.hide() # get image info raw_image_calibration = raw.getCalibration() @@ -479,7 +481,7 @@ if not os.path.exists( str(output_dir) ): # open ROIS and show on image open_rois_from_zip( rm, str(input_rois_path) ) change_all_roi_color(rm, "blue") -show_all_rois_on_image( rm, raw ) +# show_all_rois_on_image( rm, raw ) # update the log for the user IJ.log( "Now working on " + str(raw_image_title) ) @@ -551,16 +553,16 @@ rt.save(output_dir + "/" + raw_image_title + "_fibertyping_results.csv") # dress up the original image, save a overlay-png, present original to the user raw.show() show_all_rois_on_image( rm, raw ) -raw.setDisplayMode(IJ.COMPOSITE) +# raw.setDisplayMode(IJ.COMPOSITE) enhance_contrast( raw ) IJ.run("From ROI Manager", "") # ROIs -> overlays so they show up in the saved png qc_duplicate = raw.duplicate() IJ.saveAs(qc_duplicate, "PNG", output_dir + "/" + raw_image_title + "_fibertyping") qc_duplicate.close() wm.toFront( raw.getWindow() ) -IJ.run("Remove Overlay", "") -raw.setDisplayMode(IJ.GRAYSCALE) -show_all_rois_on_image( rm, raw ) +# IJ.run("Remove Overlay", "") +# raw.setDisplayMode(IJ.GRAYSCALE) +# show_all_rois_on_image( rm, raw ) total_execution_time_min = (time.time() - execution_start_time) / 60.0 IJ.log("total time in minutes: " + str(total_execution_time_min)) IJ.log( "~~ all done ~~" ) -- GitLab