Skip to content
Snippets Groups Projects

3d removal of background

1 file
+ 12
9
Compare changes
  • Side-by-side
  • Inline
+ 12
9
@@ -6,6 +6,8 @@ import numpy as np
from scipy import ndimage
from skimage import morphology
from qim3d.io.logger import log
__all__ = [
"Gaussian",
"Median",
@@ -220,17 +222,18 @@ def tophat(vol, **kwargs):
Remove background from the volume
Args:
vol: The volume to remove background from
radius: The radius of the structuring element
background_dark: If the background is dark or bright (default: True)
radius: The radius of the structuring element (default: 1)
background: color of the background, 'dark' or 'bright' (default: 'dark'). If 'bright', volume will be inverted.
Returns:
vol: The volume with background removed
"""
background_dark = kwargs["background_dark"] if "background_dark" in kwargs else True
radius = kwargs["radius"] if "radius" in kwargs else 3
radius = kwargs["radius"] if "radius" in kwargs else 1
background = kwargs["background"] if "background" in kwargs else "dark"
if background == "bright":
log.info("Bright background selected, volume will be inverted.")
vol = np.invert(vol)
selem = morphology.ball(radius)
if background_dark:
vol = vol - morphology.white_tophat(vol, selem)
else:
vol = morphology.black_tophat(vol, selem) - vol
vol = vol - morphology.white_tophat(vol, selem)
return vol
Loading