Skip to content
Snippets Groups Projects

Refactoring of blob detection

5 files
+ 123
181
Compare changes
  • Side-by-side
  • Inline

Files

+ 16
21
``` python
``` python
import qim3d
import qim3d
%% Output
WARNING:root:Could not load CuPy: No module named 'cupy'
This notebook shows how to do **blob detection** in a 3D volume using the `qim3d` library.
This notebook shows how to do **blob detection** in a 3D volume using the `qim3d` library.
Blob detection is done by initializing a `qim3d.processing.Blob` object, and then calling the `qim3d.processing.Blob.detect` method. The `qim3d.processing.Blob.detect` method detects blobs by using the Difference of Gaussian (DoG) blob detection method, and returns an array `blobs` with the blobs found in the volume stored as `(p, r, c, radius)`. Subsequently, a binary mask of the volume can be retrieved with the `qim3d.processing.get_mask` method, in which the found blobs are marked as `True`.
Blob detection is done by using the `qim3d.processing.blob_detection` method, which detects blobs by using the Difference of Gaussian (DoG) blob detection method, and returns two arrays:
 
- `blobs`: The blobs found in the volume stored as `(p, r, c, radius)`
 
- `binary_volume`: A binary mask of the volume with the blobs marked as `True`
%% Cell type:markdown id: tags:
%% Cell type:markdown id: tags:
%% Cell type:code id: tags:
%% Cell type:code id: tags:
%% Output
%% Output
<Figure size 1000x200 with 5 Axes>
<Figure size 1000x200 with 5 Axes>
%% Cell type:code id: tags:
%% Cell type:code id: tags:
``` python
``` python
# Initialize blob detector
# Detect blobs, and get binary mask
blob_detector = qim3d.processing.Blob(
blobs, mask = qim3d.processing.blob_detection(
background = "bright",
cement_filtered,
min_sigma = 1,
min_sigma=1,
max_sigma = 8,
max_sigma=8,
threshold = 0.001,
threshold=0.001,
overlap = 0.1
overlap=0.1,
 
background="bright"
)
)
# Detect blobs in filtered volume
blobs = blob_detector.detect(vol = cement_filtered)
# Number of blobs found
# Number of blobs found
print(f'Number of blobs found in the volume: {len(blobs)} blobs')
print(f'Number of blobs found in the volume: {len(blobs)} blobs')
%% Output
%% Output
 
Bright background selected, volume will be inverted.
%% Cell type:code id: tags:
%% Cell type:code id: tags:
``` python
``` python
# Visualize blobs on slices of cement volume
# Visualize blobs on slices of cement volume
qim3d.viz.detection.circles(blobs, cement, show = True)
qim3d.viz.detection.circles(blobs, cement, alpha = 0.8, show = True, color = 'red')
%% Output
%% Output
%% Cell type:markdown id: tags:
%% Cell type:markdown id: tags:
**Get binary mask of detected blobs**
**Binary mask of detected blobs**
%% Cell type:code id: tags:
%% Cell type:code id: tags:
``` python
``` python
# Get binary mask of detected blobs
# Visualize binary mask
mask = blob_detector.get_mask()
# Visualize mask
qim3d.viz.slicer(mask)
qim3d.viz.slicer(mask)
%% Output
%% Output
interactive(children=(IntSlider(value=64, description='Slice', max=127), Output()), layout=Layout(align_items=…
interactive(children=(IntSlider(value=64, description='Slice', max=127), Output()), layout=Layout(align_items=…
Loading