diff --git a/2d_spots_in_fibers.py b/2d_spots_in_fibers.py index 18161e8e6d97bd6796063dc021df1ea18bb1d2fe..78054efaa84a738fe5e01f8759b05c2dfddef05e 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()