Skip to content
Snippets Groups Projects
Commit 84da534c authored by fima's avatar fima :beers:
Browse files

refactoring and docs

parent 814cb449
No related branches found
No related tags found
1 merge request!683d removal of background
This commit is part of merge request !68. Comments created here will be created in the context of that merge request.
docs/assets/screenshots/operations-remove_background_after.png

71.7 KiB

docs/assets/screenshots/operations-remove_background_before.png

128 KiB

# Processing data # Processing data
`qim3d` provides various tools for 3D image processing. Here, we provide a suite of powerful functionalities designed specifically for 3D image analysis and processing. From filter pipelines to structure tensor computation and blob detection, `qim3d` equips you with the tools you need to extract meaningful insights from your data. Here, we provide functionalities designed specifically for 3D image analysis and processing. From filter pipelines to structure tensor computation and blob detection, `qim3d` equips you with the tools you need to extract meaningful insights from your data.
::: qim3d.processing ::: qim3d.processing
options: options:
...@@ -10,3 +10,8 @@ ...@@ -10,3 +10,8 @@
- get_3d_cc - get_3d_cc
- Pipeline - Pipeline
- Blob - Blob
::: qim3d.processing.operations
options:
members:
- remove_background
...@@ -18,6 +18,7 @@ And remember to keep your pip installation [up to date](/qim3d/#upgrade) so that ...@@ -18,6 +18,7 @@ And remember to keep your pip installation [up to date](/qim3d/#upgrade) so that
- Support for loading DICOM files with `qim3d.io.load`🎉 - Support for loading DICOM files with `qim3d.io.load`🎉
- Introduction of `qim3d.processing.get_3d_cc` for 3D connected components and `qim3d.viz.plot_cc` for associated visualization 🎉 - Introduction of `qim3d.processing.get_3d_cc` for 3D connected components and `qim3d.viz.plot_cc` for associated visualization 🎉
- Introduction of `qim3d.viz.colormaps` for easy visualization of e.g. multi-label segmentation results 🎉 - Introduction of `qim3d.viz.colormaps` for easy visualization of e.g. multi-label segmentation results 🎉
- Introduction of `qim3d.processing.operations.background_removal` 🎉
### v0.3.2 (23/02/2024) ### v0.3.2 (23/02/2024)
......
import numpy as np
import qim3d.processing.filters as filters import qim3d.processing.filters as filters
def remove_background(vol, size=2, radius=3, background="dark", **kwargs): def remove_background(
vol: np.ndarray,
median_filter_size: int = 2,
min_object_radius: int = 3,
background: str = "dark",
**median_kwargs
) -> np.ndarray:
""" """
Remove background from a volume using a median filter followed by a tophat filter. Remove background from a volume using a qim3d filters.
Args: Args:
vol: The volume to remove background from. vol (np.ndarray): The volume to remove background from.
size: The size of the median filter (default: 2). median_filter_size (int, optional): The size of the median filter. Defaults to 2.
radius: The radius of the structuring element for the median filter (default: 3). min_object_radius (int, optional): The radius of the structuring element for the tophat filter. Defaults to 3.
background: The background type ('dark' or 'bright', default: 'dark'). background (str, optional): The background type. Can be 'dark' or 'bright'. Defaults to 'dark'.
**kwargs: Additional keyword arguments for the Median filter. **median_kwargs: Additional keyword arguments for the Median filter.
Returns: Returns:
vol: The volume with background removed. np.ndarray: The volume with background removed.
Example:
```python
import qim3d
vol = qim3d.examples.cement_128x128x128
qim3d.viz.slices(vol, vmin=0, vmax=255)
```
![operations-remove_background_before](assets/screenshots/operations-remove_background_before.png)
```python
vol_filtered = qim3d.processing.operations.remove_background(vol,
min_object_radius=3,
background="bright")
qim3d.viz.slices(vol_filtered, vmin=0, vmax=255)
```
![operations-remove_background_after](assets/screenshots/operations-remove_background_after.png)
""" """
# Create a pipeline with a median filter and a tophat filter # Create a pipeline with a median filter and a tophat filter
pipeline = filters.Pipeline( pipeline = filters.Pipeline(
filters.Median(size=size, **kwargs), filters.Median(size=median_filter_size, **median_kwargs),
filters.Tophat(radius=radius, background=background), filters.Tophat(radius=min_object_radius, background=background),
) )
# Apply the pipeline to the volume # Apply the pipeline to the volume
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment