From 312bc8e763fb35d0043f6dc6b847526de876fbc6 Mon Sep 17 00:00:00 2001 From: schlda00 <kai.schleicher@unibas.ch> Date: Fri, 25 Apr 2025 13:40:28 +0200 Subject: [PATCH] Add optional calibration parameter --- 2d_spots_in_fibers.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/2d_spots_in_fibers.py b/2d_spots_in_fibers.py index 18161e8..78054ef 100644 --- a/2d_spots_in_fibers.py +++ b/2d_spots_in_fibers.py @@ -227,7 +227,7 @@ def get_threshold_from_method(imp, method): return threshold_value -def convert_to_binary(imp, threshold=1, scale_binary=True): +def convert_to_binary(imp, threshold=1, scale_binary=True, cal=None): """Convert grayscale image to a mask / binary image Parameters @@ -238,6 +238,8 @@ def convert_to_binary(imp, threshold=1, scale_binary=True): the threshold above which pixels are considered foreground, by default 1 scale_binary : bool, optional scale the mask image from 0/255 to 0/1, by default True + cal : ImagePlus Calibration, optional + apply the calibration if given, by default None Returns ------- @@ -257,6 +259,9 @@ def convert_to_binary(imp, threshold=1, scale_binary=True): IJ.run(mask_imp, "Divide...", "value=255") IJ.run(mask_imp, "Enhance Contrast", "saturated=0.35") mask_imp.changes = False + + if cal != None: + mask_imp.setCalibration(cal) return mask_imp @@ -502,7 +507,7 @@ quality_thresholds = quality_thresholds_string.split(",") dapi_channel = BFopen_image(path_to_image, dapi_channel_number, series_number) if threshold <= 0: threshold = get_threshold_from_method(dapi_channel, "otsu") -dapi_binary = convert_to_binary(dapi_channel, threshold) +dapi_binary = convert_to_binary(dapi_channel, threshold, cal=dapi_channel.getCalibration()) # detect spots and count them per fiber results_table = ResultsTable() -- GitLab