Morphology
Morphological operations for volumetric data.
qim3d.morphology.black_tophat
Performs the black top-hat transform on a 3D volume.
The black top-hat transform is defined as the difference between the morphological closing of the volume and the original volume (Closing - Input). It is used to extract dark features and valleys that are smaller than the structuring element (kernel) from a brighter background. This is particularly effective for background correction or isolating small dark structures in a non-uniformly lit image.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
volume
|
ndarray
|
The input 3D volume. |
required |
kernel
|
(int, tuple or ndarray)
|
The structuring element. An int gives a cube of that side length, a tuple of 3 ints a box of that shape, and a 3D array is used directly as the footprint. |
required |
method
|
Literal['scipy.ndimage']
|
The backend implementation to use. Currently only 'scipy.ndimage' is supported. Defaults to 'scipy.ndimage'. |
'scipy.ndimage'
|
**kwargs
|
Any
|
Additional keyword arguments passed to the underlying method. |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
bothat_vol |
ndarray
|
The processed volume containing the extracted dark features. |
Example
Source code in qim3d/morphology/_common_morphologies.py
qim3d.morphology.closing
Performs morphological closing on a 3D volume.
Closing is defined as a dilation followed by an erosion. It is primarily used to fill small dark holes, cracks, or gaps within bright objects while preserving their overall shape and size. It smooths object contours by fusing narrow breaks and filling small depressions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
volume
|
ndarray
|
The input 3D volume. |
required |
kernel
|
(int, tuple or ndarray)
|
The structuring element. An int gives a cube of that side length, a tuple of 3 ints a box of that shape, and a 3D array is used directly as the footprint. |
required |
method
|
Literal['scipy.ndimage']
|
The backend implementation to use. Currently only 'scipy.ndimage' is supported. Defaults to 'scipy.ndimage'. |
'scipy.ndimage'
|
**kwargs
|
Any
|
Additional keyword arguments passed to the underlying method. |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
closed_vol |
ndarray
|
The closed volume. |
Example
Source code in qim3d/morphology/_common_morphologies.py
qim3d.morphology.dilate
Performs morphological dilation on a 3D volume.
Dilation enlarges bright regions (foreground) and shrinks dark regions (background). It is commonly used to close small holes, connect disjoint features, or thicken object boundaries.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
volume
|
ndarray
|
The input 3D volume. |
required |
kernel
|
(int, tuple or ndarray)
|
The structuring element. An int gives a cube of that side length, a tuple of 3 ints a box of that shape, and a 3D array is used directly as the footprint. |
required |
method
|
Literal['scipy.ndimage']
|
The backend implementation to use. Currently only 'scipy.ndimage' is supported. Defaults to 'scipy.ndimage'. |
'scipy.ndimage'
|
**kwargs
|
Any
|
Additional keyword arguments passed to the underlying method. |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
dilated_vol |
ndarray
|
The dilated volume. |
Example
Source code in qim3d/morphology/_common_morphologies.py
qim3d.morphology.erode
Performs morphological erosion on a 3D volume.
Erosion shrinks bright regions (foreground) and enlarges dark regions (background). It is commonly used to remove small noise (salt noise), detach touching objects, or thin out features.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
volume
|
ndarray
|
The input 3D volume. |
required |
kernel
|
(int, tuple or ndarray)
|
The structuring element. An int gives a cube of that side length, a tuple of 3 ints a box of that shape, and a 3D array is used directly as the footprint. |
required |
method
|
Literal['scipy.ndimage']
|
The backend implementation to use. Currently only 'scipy.ndimage' is supported. Defaults to 'scipy.ndimage'. |
'scipy.ndimage'
|
**kwargs
|
Any
|
Additional keyword arguments passed to the underlying method. |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
eroded_vol |
ndarray
|
The eroded volume. |
Example
Source code in qim3d/morphology/_common_morphologies.py
qim3d.morphology.opening
Performs morphological opening on a 3D volume.
Opening is defined as an erosion followed by a dilation. It is primarily used to remove small bright objects (salt noise) from the background while preserving the shape and size of larger objects. It smooths object contours by breaking narrow isthmuses and eliminating thin protrusions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
volume
|
ndarray
|
The input 3D volume. |
required |
kernel
|
(int, tuple or ndarray)
|
The structuring element. An int gives a cube of that side length, a tuple of 3 ints a box of that shape, and a 3D array is used directly as the footprint. |
required |
method
|
Literal['scipy.ndimage']
|
The backend implementation to use. Currently only 'scipy.ndimage' is supported. Defaults to 'scipy.ndimage'. |
'scipy.ndimage'
|
**kwargs
|
Any
|
Additional keyword arguments passed to the underlying method. |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
opened_vol |
ndarray
|
The opened volume. |
Example
import qim3d
import numpy as np
# Generate tubular synthetic blob
vol = qim3d.generate.volume(noise_scale=0.025, seed=50)
# Add noise to the data
vol_noised = qim3d.generate.background(
background_shape=vol.shape,
apply_method = 'add',
apply_to = vol
)
# Visualize synthetic volume
qim3d.viz.volumetric(vol_noised, grid_visible=True)
Source code in qim3d/morphology/_common_morphologies.py
qim3d.morphology.white_tophat
Performs the white top-hat transform on a 3D volume.
The white top-hat transform is defined as the difference between the original volume and its morphological opening (Input - Opening). It is used to extract bright features and peaks that are smaller than the structuring element (kernel) from a darker background. This is a powerful tool for background subtraction, enhancing small bright spots, or correcting uneven illumination in a volume.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
volume
|
ndarray
|
The input 3D volume. |
required |
kernel
|
(int, tuple or ndarray)
|
The structuring element. An int gives a cube of that side length, a tuple of 3 ints a box of that shape, and a 3D array is used directly as the footprint. |
required |
method
|
Literal['scipy.ndimage']
|
The backend implementation to use. Currently only 'scipy.ndimage' is supported. Defaults to 'scipy.ndimage'. |
'scipy.ndimage'
|
**kwargs
|
Any
|
Additional keyword arguments passed to the underlying method. |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
tophat_vol |
ndarray
|
The processed volume containing the extracted bright features. |