|
3 | 3 | import os |
4 | 4 |
|
5 | 5 | import 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 |
7 | 9 | from ..imagej import bioformats # pylint: disable-msg=no-name-in-module |
8 | 10 | from ..imagej import misc, projections |
9 | 11 | from ..log import LOG as log |
@@ -179,3 +181,38 @@ def process_files(files, outpath, model_file, fmt): |
179 | 181 |
|
180 | 182 | if model: |
181 | 183 | model.close() |
| 184 | + |
| 185 | +def simple_flatfield_correction(imp, sigma=20.0): |
| 186 | + """Performs a simple flatfield correction to a given ImagePlus stack. |
| 187 | +
|
| 188 | + The function returns a 32-bit corrected flatfield image. |
| 189 | +
|
| 190 | + Parameters |
| 191 | + ---------- |
| 192 | + imp : ij.ImagePlus |
| 193 | + The input stack to be projected. |
| 194 | + sigma: float, optional |
| 195 | + The sigma value for the Gaussian blur, default=20.0 |
| 196 | +
|
| 197 | + Returns |
| 198 | + ------- |
| 199 | + ij.ImagePlus |
| 200 | + The 32-bit image result of flatfield correction |
| 201 | +
|
| 202 | + """ |
| 203 | + flatfield = imp.duplicate() |
| 204 | + sigma_str = "sigma=" + str(sigma) |
| 205 | + |
| 206 | + IJ.run(flatfield, "Gaussian Blur...", sigma_str) |
| 207 | + stats = StackStatistics(flatfield) |
| 208 | + |
| 209 | + # Normalize image to the highest value of original (requires 32-bit image) |
| 210 | + IJ.run(flatfield, "32-bit", "") |
| 211 | + IJ.run( |
| 212 | + flatfield, |
| 213 | + "Divide...", |
| 214 | + "value=" + str(stats.max)) |
| 215 | + ic = ImageCalculator() |
| 216 | + flatfield_corrected = ic.run("Divide create", imp, flatfield) |
| 217 | + |
| 218 | + return flatfield_corrected |
0 commit comments