Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 42 additions & 3 deletions src/imcflibs/imagej/processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand All @@ -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.

Expand Down
Loading