diff --git a/2c_fibertyping.py b/2c_fibertyping.py index 7497a4c78c0b8db3e344743927d6b7c422277bbe..125b99c644eb9b7c33013dd85b7c420d66b3af4c 100644 --- a/2c_fibertyping.py +++ b/2c_fibertyping.py @@ -1,15 +1,15 @@ # @ String (visibility=MESSAGE, value="<html><b> Welcome to Myosoft! </b></html>") msg1 # @ File (label="Select fiber-ROIs zip-file", style="file") roi_zip # @ File (label="Select image file", description="select your image") path_to_image -#@ File (label="Select directory for output", style="directory") output_dir -#@ Boolean (label="close image after processing", description="tick this box when using batch mode", value=False) close_raw -#@ String (visibility=MESSAGE, value="<html><b> channel positions in the hyperstack </b></html>") msg5 -#@ Integer (label="Fiber staining 1 channel number (0=n.a.)", style="slider", min=0, max=5, value=1) fiber_channel_1 -#@ Integer (label="Fiber staining 2 channel number (0=n.a.)", style="slider", min=0, max=5, value=2) fiber_channel_2 -#@ Integer (label="Fiber staining 3 channel number (0=n.a.)", style="slider", min=0, max=5, value=3) fiber_channel_3 -#@ Integer (label="minimum fiber intensity (0=auto)", description="0 = automatic threshold detection", value=0) min_fiber_intensity_1 -#@ Integer (label="minimum fiber intensity (0=auto)", description="0 = automatic threshold detection", value=0) min_fiber_intensity_2 -#@ Integer (label="minimum fiber intensity (0=auto)", description="0 = automatic threshold detection", value=0) min_fiber_intensity_3 +# @ File (label="Select directory for output", style="directory") output_dir +# @ Boolean (label="close image after processing", description="tick this box when using batch mode", value=False) close_raw +# @ String (visibility=MESSAGE, value="<html><b> channel positions in the hyperstack </b></html>") msg5 +# @ Integer (label="Fiber staining 1 channel number (0=n.a.)", style="slider", min=0, max=5, value=1) fiber_channel_1 +# @ Integer (label="Fiber staining 2 channel number (0=n.a.)", style="slider", min=0, max=5, value=2) fiber_channel_2 +# @ Integer (label="Fiber staining 3 channel number (0=n.a.)", style="slider", min=0, max=5, value=3) fiber_channel_3 +# @ Integer (label="minimum fiber intensity (0=auto)", description="0 = automatic threshold detection", value=0) min_fiber_intensity_1 +# @ Integer (label="minimum fiber intensity (0=auto)", description="0 = automatic threshold detection", value=0) min_fiber_intensity_2 +# @ Integer (label="minimum fiber intensity (0=auto)", description="0 = automatic threshold detection", value=0) min_fiber_intensity_3 # @ ResultsTable rt # @ RoiManager rm @@ -50,7 +50,7 @@ def get_threshold_from_method(imp, channel, method): A list containing the upper and the lower threshold (integer values). """ # Set the channel of the imp to the desired channel - imp.setC(channel) # starts at 1 + imp.setC(channel) # starts at 1 # Get the processor of the imp ip = imp.getProcessor() # Set the AutoThreshold method to the desired method @@ -159,28 +159,35 @@ if __name__ == "__main__": roimanager.load_rois_from_zip(rm, input_rois_path) roimanager.change_roi_color(rm, "blue") -# update the log for the user -IJ.log( "Now working on " + str(raw_image_title) ) -if raw_image_calibration.scaled() == False: - IJ.log("Your image is not spatially calibrated! Size measurements are only possible in [px].") -IJ.log( " -- settings used -- ") -IJ.log( "Selected fiber-ROIs zip-file = " + str(input_rois_path) ) -IJ.log( "Fiber staining 1 channel number = " + str(fiber_channel_1) ) -IJ.log( "Fiber staining 2 channel number = " + str(fiber_channel_2) ) -IJ.log( "Fiber staining 3 channel number = " + str(fiber_channel_3) ) -IJ.log( " -- settings used -- ") - -# measure size & shape, -IJ.run("Set Measurements...", "area perimeter shape feret's redirect=None decimal=4") -IJ.run("Clear Results", "") -measure_in_all_rois( raw, fiber_channel_1, rm ) + # update the log for the user + IJ.log("Now working on " + str(raw_image_title)) + if not raw_image_calibration.scaled(): + IJ.log( + "Your image is not spatially calibrated! Size measurements are only possible in [px]." + ) + IJ.log(" -- settings used -- ") + IJ.log("Selected fiber-ROIs zip-file = " + str(input_rois_path)) + IJ.log("Fiber staining 1 channel number = " + str(fiber_channel_1)) + IJ.log("Fiber staining 2 channel number = " + str(fiber_channel_2)) + IJ.log("Fiber staining 3 channel number = " + str(fiber_channel_3)) + IJ.log(" -- settings used -- ") + + # measure size & shape, + IJ.run( + "Set Measurements...", "area perimeter shape feret's redirect=None decimal=4" + ) + IJ.run("Clear Results", "") roimanager.measure_in_all_rois(raw, fiber_channel_1, rm) -# loop through the fiber channels, check if positive, add info to results table -all_fiber_channels = [fiber_channel_1, fiber_channel_2, fiber_channel_3] -all_min_fiber_intensities = [min_fiber_intensity_1, min_fiber_intensity_2, min_fiber_intensity_3] -roi_colors = ["green", "orange", "red"] -all_fiber_subsets =[ [], [], [] ] + # loop through the fiber channels, check if positive, add info to results table + all_fiber_channels = [fiber_channel_1, fiber_channel_2, fiber_channel_3] + all_min_fiber_intensities = [ + min_fiber_intensity_1, + min_fiber_intensity_2, + min_fiber_intensity_3, + ] + roi_colors = ["green", "orange", "red"] + all_fiber_subsets = [[], [], []] for index, fiber_channel in enumerate(all_fiber_channels): if fiber_channel > 0: @@ -242,24 +249,28 @@ all_fiber_subsets =[ [], [], [] ] "YES", ) -# single positive -positive_c1 = all_fiber_subsets[0] -positive_c2 = all_fiber_subsets[1] -positive_c3 = all_fiber_subsets[2] -# double positive -positive_c1_c2 = list( set(all_fiber_subsets[0]).intersection(all_fiber_subsets[1]) ) -positive_c1_c3 = list( set(all_fiber_subsets[0]).intersection(all_fiber_subsets[2]) ) -positive_c2_c3 = list( set(all_fiber_subsets[1]).intersection(all_fiber_subsets[2]) ) -# triple positive -positive_c1_c2_c3 = list( set(positive_c1_c2).intersection(all_fiber_subsets[2]) ) - -# update ROI color & results table for double and triple positives -channels = [ - (positive_c1_c2, [fiber_channel_1, fiber_channel_2], "magenta"), - (positive_c1_c3, [fiber_channel_1, fiber_channel_3], "yellow"), - (positive_c2_c3, [fiber_channel_2, fiber_channel_3], "cyan"), - (positive_c1_c2_c3, [fiber_channel_1, fiber_channel_2, fiber_channel_3], "white") -] + # single positive + positive_c1 = all_fiber_subsets[0] + positive_c2 = all_fiber_subsets[1] + positive_c3 = all_fiber_subsets[2] + # double positive + positive_c1_c2 = list(set(all_fiber_subsets[0]).intersection(all_fiber_subsets[1])) + positive_c1_c3 = list(set(all_fiber_subsets[0]).intersection(all_fiber_subsets[2])) + positive_c2_c3 = list(set(all_fiber_subsets[1]).intersection(all_fiber_subsets[2])) + # triple positive + positive_c1_c2_c3 = list(set(positive_c1_c2).intersection(all_fiber_subsets[2])) + + # update ROI color & results table for double and triple positives + channels = [ + (positive_c1_c2, [fiber_channel_1, fiber_channel_2], "magenta"), + (positive_c1_c3, [fiber_channel_1, fiber_channel_3], "yellow"), + (positive_c2_c3, [fiber_channel_2, fiber_channel_3], "cyan"), + ( + positive_c1_c2_c3, + [fiber_channel_1, fiber_channel_2, fiber_channel_3], + "white", + ), + ] for positives, ch_nums, color in channels: if positives: @@ -289,13 +300,13 @@ channels = [ # dress up the original image, save a overlay-png, present original to the user raw.show() roimanager.show_all_rois_on_image(rm, raw) -# 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() ) + # 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.log( "Script finished. Total runtime [HH:MM:SS.ss]: "