A small package with Numba-accelerated morphological operations.
Project description
nbmorph
A small, Numba-accelerated Python package for morphological operations on 3D labeled images.
nbmorph provides a set of common morphological operations optimized for performance using Numba. It is designed to work with 3D NumPy arrays representing labeled image data, where different integer labels correspond to different objects.
Features
-
Numba-accelerated: Operations are just-in-time compiled with Numba for high performance on CPUs.
-
3D Label Image Support: All operations are designed for 3D labeled images (integer NumPy arrays).
-
Quasi-Spherical Structuring Elements: Approximates spherical structuring elements by alternating between box and diamond kernels for dilation and erosion.
-
Core Morphological Operations:
-
dilate_labels_spherical: Expands the boundaries of labeled regions by assigning the mode of the neighborhood to background voxels. -
erode_labels_spherical: Shrinks the boundaries of labeled regions. -
open_labels_spherical: Removes small noise and thin protrusions (erosion followed by dilation). -
close_labels_spherical: Fills small holes within objects (dilation followed by erosion). -
smooth_labels_spherical: Smoothes object boundaries by performing an opening followed by a closing.
-
Demonstration of the smoothing effect with varying radii and iterations on a sample image.
Installation
You can install nbmorph directly from the source directory using pip:
pip install .
Usage
Here is a basic example of how to use nbmorph to apply morphological smoothing to a 3D labeled image.
import numpy as np
import nbmorph
# Create a sample 3D labeled image
# For example, a 5x5x5 cube of label 1 in a 10x10x10 volume
labels = np.zeros((10, 10, 10), dtype=np.uint16)
labels[2:7, 2:7, 2:7] = 1
# Apply morphological smoothing with a radius of 1
smoothed_labels = nbmorph.smooth_labels_spherical(labels, radius=1)
print("Smoothing complete. The smoothed labels are in the 'smoothed_labels' array.")
Operations
The core functions of the library are:
-
nbmorph.dilate_labels_spherical(labels, radius=1) -
nbmorph.erode_labels_spherical(labels, radius=1) -
nbmorph.open_labels_spherical(labels, radius=1, iterations=1) -
nbmorph.close_labels_spherical(labels, radius=1, iterations=1) -
nbmorph.smooth_labels_spherical(labels, radius=1, iterations=1)
Testing
Tests are written using pytest. To run the tests, first install the test dependencies and then run pytest:
pip install .[test]
pytest
Benchmarking
A benchmark script is included in the scripts directory:
python scripts/benchmark.py
License
This project is licensed under the MIT License - see the LICENSE file for details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file nbmorph-0.1.0.tar.gz.
File metadata
- Download URL: nbmorph-0.1.0.tar.gz
- Upload date:
- Size: 15.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
331fae1d6e64547655cdd32a170d3c8ac3eff07f7cbe6e8189b014536292f8a8
|
|
| MD5 |
57e6765756c36ad90c67bf0bf60cbbcb
|
|
| BLAKE2b-256 |
dbb6f089a8f570516d3c5cc4c12ea4ea4ac9857551f54578c76313b8abad401d
|
Provenance
The following attestation bundles were made for nbmorph-0.1.0.tar.gz:
Publisher:
release.yaml on MariusCausemann/nbmorph
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
nbmorph-0.1.0.tar.gz -
Subject digest:
331fae1d6e64547655cdd32a170d3c8ac3eff07f7cbe6e8189b014536292f8a8 - Sigstore transparency entry: 537616071
- Sigstore integration time:
-
Permalink:
MariusCausemann/nbmorph@c40135038f2662a6d949ca3456e2d01671db001a -
Branch / Tag:
refs/tags/v0.1 - Owner: https://github.com/MariusCausemann
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yaml@c40135038f2662a6d949ca3456e2d01671db001a -
Trigger Event:
push
-
Statement type:
File details
Details for the file nbmorph-0.1.0-py3-none-any.whl.
File metadata
- Download URL: nbmorph-0.1.0-py3-none-any.whl
- Upload date:
- Size: 13.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
23bd2c6d619d127f68d972d788cb0b70d755e45669f709ce936ebe02d652257f
|
|
| MD5 |
d5fb689f428ccab67cc38b24f65b5f30
|
|
| BLAKE2b-256 |
3b7a33af040cd7492bb253da954e565d7cee7ff534f717271c22ae86438fb53f
|
Provenance
The following attestation bundles were made for nbmorph-0.1.0-py3-none-any.whl:
Publisher:
release.yaml on MariusCausemann/nbmorph
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
nbmorph-0.1.0-py3-none-any.whl -
Subject digest:
23bd2c6d619d127f68d972d788cb0b70d755e45669f709ce936ebe02d652257f - Sigstore transparency entry: 537616078
- Sigstore integration time:
-
Permalink:
MariusCausemann/nbmorph@c40135038f2662a6d949ca3456e2d01671db001a -
Branch / Tag:
refs/tags/v0.1 - Owner: https://github.com/MariusCausemann
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yaml@c40135038f2662a6d949ca3456e2d01671db001a -
Trigger Event:
push
-
Statement type: