Skip to content
Snippets Groups Projects

3d removal of background

Merged s204159 requested to merge 3d_removal into main
1 file
+ 9
8
Compare changes
  • Side-by-side
  • Inline
import qim3d.processing.filters as filters
def remove_background(vol, **kwargs):
def remove_background(vol, size=2, radius=3, background="dark", **kwargs):
"""
Remove background from a volume using a median filter followed by a tophat filter.
Args:
vol: The volume to remove background from.
**kwargs: Additional keyword arguments for the tophat filter.
size: The size of the median filter (default: 2).
radius: The radius of the structuring element for the median filter (default: 3).
background: The background type ('dark' or 'bright', default: 'dark').
**kwargs: Additional keyword arguments for the Median filter.
Returns:
vol: The volume with background removed.
"""
# sets the median filter size to 2 if not specified for removing background artifacts
size = kwargs["size"] if "size" in kwargs else 2
# Create a pipeline with a median filter and a tophat filter
pipeline = filters.Pipeline(
filters.Median(size=size),
filters.Tophat(**kwargs)
filters.Median(size=size, **kwargs),
filters.Tophat(radius=radius, background=background),
)
# Apply the pipeline to the volume
return pipeline(vol)
\ No newline at end of file
return pipeline(vol)
Loading