Segmenting data
The qim3d
library provides a set of methods for data segmentation.
qim3d.segmentation
qim3d.segmentation.watershed
Apply watershed segmentation to a binary volume.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
bin_vol |
ndarray
|
Binary volume to segment. The input should be a 3D binary image where non-zero elements represent the objects to be segmented. |
required |
min_distance |
int
|
Minimum number of pixels separating peaks in the distance transform. Peaks that are too close will be merged, affecting the number of segmented objects. Default is 5. |
5
|
Returns:
Name | Type | Description |
---|---|---|
labeled_vol |
ndarray
|
A 3D array of the same shape as the input |
num_labels |
int
|
The total number of unique objects found in the labeled volume. |
Example
import qim3d
vol = qim3d.examples.cement_128x128x128
bin_vol = qim3d.filters.gaussian(vol, sigma = 2)<60
fig1 = qim3d.viz.slices_grid(bin_vol, slice_axis=1, display_figure=True)

labeled_volume, num_labels = qim3d.segmentation.watershed(bin_vol)
cmap = qim3d.viz.colormaps.segmentation(num_labels)
fig2 = qim3d.viz.slices_grid(labeled_volume, slice_axis=1, color_map=cmap, display_figure=True)

Source code in qim3d/segmentation/_common_segmentation_methods.py
qim3d.segmentation.get_3d_cc
Returns an object (CC) containing the connected components of the input volume. Use plot_cc to visualize the connected components.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
image |
ndarray
|
An array-like object to be labeled. Any non-zero values in |
required |
Returns:
Name | Type | Description |
---|---|---|
CC |
CC
|
A ConnectedComponents object containing the connected components and the number of connected components. |