Skip to content
Snippets Groups Projects

Refactoring of blob detection

3 files
+ 28
33
Compare changes
  • Side-by-side
  • Inline

Files

+ 16
21
%% Cell type:code id: tags:
``` python
import qim3d
```
%% Output
WARNING:root:Could not load CuPy: No module named 'cupy'
%% Cell type:markdown id: tags:
### Blob detection notebook
%% Cell type:markdown id: tags:
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:
### **Example 1**: Blob detection in cement volume
%% Cell type:markdown id: tags:
**Applying Gaussian filter to volume**
%% Cell type:code id: tags:
``` python
# Import 3D volume of cement
cement = qim3d.examples.cement_128x128x128
# Visualize slices of the original cement volume
qim3d.viz.slices(cement, n_slices = 5, show = True)
# Apply Gaussian filter to the cement volume
cement_filtered = qim3d.processing.gaussian(cement, sigma = 2)
# Visualize slices of the filtered cement volume
qim3d.viz.slices(cement_filtered)
```
%% Output
<Figure size 1000x200 with 5 Axes>
%% Cell type:markdown id: tags:
**Detecting blobs in volume**
%% Cell type:code id: tags:
``` python
# Initialize blob detector
blob_detector = qim3d.processing.Blob(
background = "bright",
min_sigma = 1,
max_sigma = 8,
threshold = 0.001,
overlap = 0.1
# Detect blobs, and get binary mask
blobs, mask = qim3d.processing.blob_detection(
cement_filtered,
min_sigma=1,
max_sigma=8,
threshold=0.001,
overlap=0.1,
background="bright"
)
# Detect blobs in filtered volume
blobs = blob_detector.detect(vol = cement_filtered)
# Number of blobs found
print(f'Number of blobs found in the volume: {len(blobs)} blobs')
```
%% Output
Bright background selected, volume will be inverted.
Number of blobs found in the volume: 1813 blobs
%% Cell type:code id: tags:
``` python
# 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
interactive(children=(IntSlider(value=64, description='Slice', max=127), Output()), layout=Layout(align_items=…
%% Cell type:markdown id: tags:
**Get binary mask of detected blobs**
**Binary mask of detected blobs**
%% Cell type:code id: tags:
``` python
# Get binary mask of detected blobs
mask = blob_detector.get_mask()
# Visualize mask
# Visualize binary mask
qim3d.viz.slicer(mask)
```
%% Output
interactive(children=(IntSlider(value=64, description='Slice', max=127), Output()), layout=Layout(align_items=…
Loading