33import os
44
55import ij # pylint: disable-msg=import-error
6-
6+ from ij import IJ
7+ from ij .plugin import ImageCalculator , Concatenator
8+ from ij .process import StackStatistics , ImageProcessor
79from ..imagej import bioformats # pylint: disable-msg=no-name-in-module
810from ..imagej import misc , projections
911from ..log import LOG as log
@@ -179,3 +181,29 @@ def process_files(files, outpath, model_file, fmt):
179181
180182 if model :
181183 model .close ()
184+
185+ def simple_flatfield_correction (imp , sigma = 20.0 ):
186+ """
187+ Performs a simple flatfield correction to a given ImagePlus stack and returns a 32-bit corrected flatfield image.
188+ Parameters
189+ ----------
190+ imp : ij.ImagePlus
191+ The input stack to be projected.
192+ sigma: double, default 20.0
193+ The sigma value for the Gaussian blur, default = 20.0
194+ Returns
195+ -------
196+ ij.ImagePlus
197+ The 32-bit image result of the flatfield correction
198+
199+ """
200+ flatfield = imp .duplicate ()
201+ sigma_str = "sigma=" + str (sigma )
202+ IJ .run (flatfield , "Gaussian Blur..." , sigma_str ) # Apply a gaussian blur
203+ stats = StackStatistics (flatfield )
204+ IJ .run (flatfield , "32-bit" , "" ) # Make a 32 bit version of the image
205+ IJ .run (flatfield , "Divide..." , "value=" + str (stats .max )) # Normalize 32 bit image to the highest value of original
206+ ic = ImageCalculator ()
207+ flatfield_corrected = ic .run ("Divide create" , imp , flatfield )
208+
209+ return flatfield_corrected
0 commit comments