diff --git a/src/imcflibs/imagej/processing.py b/src/imcflibs/imagej/processing.py index 41a6b9a..0aa223c 100644 --- a/src/imcflibs/imagej/processing.py +++ b/src/imcflibs/imagej/processing.py @@ -66,7 +66,14 @@ def apply_filter(imp, filter_method, filter_radius, do_3d=False): return imageplus -def apply_rollingball_bg_subtraction(imp, rolling_ball_radius, do_3d=False): +def apply_rollingball_bg_subtraction( + imp, + rolling_ball_radius, + light_background=False, + sliding=False, + disable=False, + do_3d=False, +): """Perform background subtraction using a rolling ball method. Parameters @@ -75,6 +82,12 @@ def apply_rollingball_bg_subtraction(imp, rolling_ball_radius, do_3d=False): Input ImagePlus to filter and threshold rolling_ball_radius : int Radius of the rolling ball filter to use + light_background : bool, optional + If set to True, will treat the background as light, by default False + sliding : bool, optional + If set to True, will do a sliding window approach, by default False + disable : bool, optional + If set to True, will disable the smoothing, by default False do_3d : bool, optional If set to True, will do a 3D filtering, by default False @@ -85,16 +98,42 @@ def apply_rollingball_bg_subtraction(imp, rolling_ball_radius, do_3d=False): """ log.info("Applying rolling ball with radius %d" % rolling_ball_radius) - options = "rolling=" + str(rolling_ball_radius) + " stack" if do_3d else "" + options = rolling_ball_options( + rolling_ball_radius, + light_background=light_background, + sliding=sliding, + disable=disable, + do_3d=do_3d, + ) log.debug("Background subtraction options: %s" % options) imageplus = imp.duplicate() - IJ.run(imageplus, "Substract Background...", options) + IJ.run(imageplus, "Subtract Background...", options) return imageplus +def rolling_ball_options( + rolling_ball_radius, + light_background=False, + sliding=False, + disable=False, + do_3d=False, +): + """Return the option string for rolling ball background subtraction.""" + parts = ["rolling=" + str(rolling_ball_radius)] + if light_background: + parts.append("light") + if sliding: + parts.append("sliding") + if disable: + parts.append("disable") + if do_3d: + parts.append("stack") + return " ".join(parts) + + def apply_threshold(imp, threshold_method, do_3d=True): """Apply a threshold method to the input ImagePlus.