From 948a18cc9b8b229f8f5da1f8b1aad93ee1e25b24 Mon Sep 17 00:00:00 2001 From: Laurent Guerard <laurent.guerard@unibas.ch> Date: Wed, 8 Jan 2025 14:39:06 +0100 Subject: [PATCH] Add background correction method --- 1_identify_fibers.py | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/1_identify_fibers.py b/1_identify_fibers.py index 2debeef..6017fda 100755 --- a/1_identify_fibers.py +++ b/1_identify_fibers.py @@ -107,20 +107,31 @@ def fix_BF_czi_imagetitle(imp): return image_title -def preprocess_membrane_channel(imp): - """apply myosoft pre-processing steps for the membrane channel +def do_background_correction(imp, gaussian_radius=20): + """Perform background correction on an image. + + This is done by applying a Gaussian blur to the image and then dividing the + original image by the blurred image. Parameters ---------- - imp : ImagePlus - a single channel image of the membrane staining + imp : ij.ImagePlus + The image to be corrected. + gaussian_radius : int + The radius of the Gaussian filter to be used. Default value is 20. + + Returns + ------- + ij.ImagePlus + The background-corrected image. """ - IJ.run(imp, "Enhance Contrast", "saturated=0.35") - IJ.run(imp, "Apply LUT", "") - IJ.run(imp, "Enhance Contrast", "saturated=1") - IJ.run(imp, "8-bit", "") - IJ.run(imp, "Invert", "") - IJ.run(imp, "Convolve...", "text1=[-1.0 -1.0 -1.0 -1.0 -1.0\n-1.0 -1.0 -1.0 -1.0 0\n-1.0 -1.0 24.0 -1.0 -1.0\n-1.0 -1.0 -1.0 -1.0 -1.0\n-1.0 -1.0 -1.0 -1.0 0] normalize") + imp_bgd = imp.duplicate() + IJ.run( + imp_bgd, + "Gaussian Blur...", + "sigma=" + str(gaussian_radius) + " scaled", + ) + return ImageCalculator.run(imp, imp_bgd, "Divide create 32-bit") def get_threshold_from_method(imp, channel, method): -- GitLab