nbmorph 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
nbmorph-0.1.0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) [2025] [Marius Causemann]
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
nbmorph-0.1.0/PKG-INFO ADDED
@@ -0,0 +1,136 @@
1
+ Metadata-Version: 2.4
2
+ Name: nbmorph
3
+ Version: 0.1.0
4
+ Summary: A small package with Numba-accelerated morphological operations.
5
+ Author-email: Marius Causemann <mariusca@simula.no>
6
+ License: MIT License
7
+
8
+ Copyright (c) [2025] [Marius Causemann]
9
+
10
+ Permission is hereby granted, free of charge, to any person obtaining a copy
11
+ of this software and associated documentation files (the "Software"), to deal
12
+ in the Software without restriction, including without limitation the rights
13
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14
+ copies of the Software, and to permit persons to whom the Software is
15
+ furnished to do so, subject to the following conditions:
16
+
17
+ The above copyright notice and this permission notice shall be included in all
18
+ copies or substantial portions of the Software.
19
+
20
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26
+ SOFTWARE.
27
+ Classifier: Programming Language :: Python :: 3
28
+ Classifier: License :: OSI Approved :: MIT License
29
+ Classifier: Operating System :: OS Independent
30
+ Classifier: Intended Audience :: Science/Research
31
+ Classifier: Topic :: Scientific/Engineering :: Image Processing
32
+ Requires-Python: >=3.8
33
+ Description-Content-Type: text/markdown
34
+ License-File: LICENSE
35
+ Requires-Dist: numpy
36
+ Requires-Dist: numba
37
+ Provides-Extra: test
38
+ Requires-Dist: pytest; extra == "test"
39
+ Requires-Dist: pytest-cov; extra == "test"
40
+ Requires-Dist: fastmorph; extra == "test"
41
+ Dynamic: license-file
42
+
43
+ # nbmorph
44
+
45
+ A small, Numba-accelerated Python package for morphological operations on 3D labeled images.
46
+
47
+ `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.
48
+
49
+ ## Features
50
+
51
+ * **Numba-accelerated:** Operations are just-in-time compiled with Numba for high performance on CPUs.
52
+
53
+ * **3D Label Image Support:** All operations are designed for 3D labeled images (integer NumPy arrays).
54
+
55
+ * **Quasi-Spherical Structuring Elements:** Approximates spherical structuring elements by alternating between box and diamond kernels for dilation and erosion.
56
+
57
+ * **Core Morphological Operations:**
58
+
59
+ * `dilate_labels_spherical`: Expands the boundaries of labeled regions by assigning the mode of the neighborhood to background voxels.
60
+
61
+ * `erode_labels_spherical`: Shrinks the boundaries of labeled regions.
62
+
63
+ * `open_labels_spherical`: Removes small noise and thin protrusions (erosion followed by dilation).
64
+
65
+ * `close_labels_spherical`: Fills small holes within objects (dilation followed by erosion).
66
+
67
+ * `smooth_labels_spherical`: Smoothes object boundaries by performing an opening followed by a closing.
68
+
69
+ ![Effect of Morphological Smoothing](img/smoothing_effect.png)
70
+ *Demonstration of the smoothing effect with varying radii and iterations on a sample image.*
71
+
72
+
73
+ ## Installation
74
+
75
+ You can install `nbmorph` directly from the source directory using pip:
76
+
77
+ ```
78
+ pip install .
79
+
80
+ ```
81
+
82
+
83
+ ## Usage
84
+
85
+ Here is a basic example of how to use `nbmorph` to apply morphological smoothing to a 3D labeled image.
86
+
87
+ ```
88
+ import numpy as np
89
+ import nbmorph
90
+
91
+ # Create a sample 3D labeled image
92
+ # For example, a 5x5x5 cube of label 1 in a 10x10x10 volume
93
+ labels = np.zeros((10, 10, 10), dtype=np.uint16)
94
+ labels[2:7, 2:7, 2:7] = 1
95
+
96
+ # Apply morphological smoothing with a radius of 1
97
+ smoothed_labels = nbmorph.smooth_labels_spherical(labels, radius=1)
98
+
99
+ print("Smoothing complete. The smoothed labels are in the 'smoothed_labels' array.")
100
+
101
+ ```
102
+
103
+ ## Operations
104
+
105
+ The core functions of the library are:
106
+
107
+ * `nbmorph.dilate_labels_spherical(labels, radius=1)`
108
+
109
+ * `nbmorph.erode_labels_spherical(labels, radius=1)`
110
+
111
+ * `nbmorph.open_labels_spherical(labels, radius=1, iterations=1)`
112
+
113
+ * `nbmorph.close_labels_spherical(labels, radius=1, iterations=1)`
114
+
115
+ * `nbmorph.smooth_labels_spherical(labels, radius=1, iterations=1)`
116
+
117
+ ## Testing
118
+
119
+ Tests are written using `pytest`. To run the tests, first install the test dependencies and then run `pytest`:
120
+
121
+ ```
122
+ pip install .[test]
123
+ pytest
124
+ ```
125
+
126
+ ## Benchmarking
127
+
128
+ A benchmark script is included in the `scripts` directory:
129
+
130
+ ```
131
+ python scripts/benchmark.py
132
+ ```
133
+
134
+ ## License
135
+
136
+ This project is licensed under the MIT License - see the `LICENSE` file for details.
@@ -0,0 +1,94 @@
1
+ # nbmorph
2
+
3
+ A small, Numba-accelerated Python package for morphological operations on 3D labeled images.
4
+
5
+ `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.
6
+
7
+ ## Features
8
+
9
+ * **Numba-accelerated:** Operations are just-in-time compiled with Numba for high performance on CPUs.
10
+
11
+ * **3D Label Image Support:** All operations are designed for 3D labeled images (integer NumPy arrays).
12
+
13
+ * **Quasi-Spherical Structuring Elements:** Approximates spherical structuring elements by alternating between box and diamond kernels for dilation and erosion.
14
+
15
+ * **Core Morphological Operations:**
16
+
17
+ * `dilate_labels_spherical`: Expands the boundaries of labeled regions by assigning the mode of the neighborhood to background voxels.
18
+
19
+ * `erode_labels_spherical`: Shrinks the boundaries of labeled regions.
20
+
21
+ * `open_labels_spherical`: Removes small noise and thin protrusions (erosion followed by dilation).
22
+
23
+ * `close_labels_spherical`: Fills small holes within objects (dilation followed by erosion).
24
+
25
+ * `smooth_labels_spherical`: Smoothes object boundaries by performing an opening followed by a closing.
26
+
27
+ ![Effect of Morphological Smoothing](img/smoothing_effect.png)
28
+ *Demonstration of the smoothing effect with varying radii and iterations on a sample image.*
29
+
30
+
31
+ ## Installation
32
+
33
+ You can install `nbmorph` directly from the source directory using pip:
34
+
35
+ ```
36
+ pip install .
37
+
38
+ ```
39
+
40
+
41
+ ## Usage
42
+
43
+ Here is a basic example of how to use `nbmorph` to apply morphological smoothing to a 3D labeled image.
44
+
45
+ ```
46
+ import numpy as np
47
+ import nbmorph
48
+
49
+ # Create a sample 3D labeled image
50
+ # For example, a 5x5x5 cube of label 1 in a 10x10x10 volume
51
+ labels = np.zeros((10, 10, 10), dtype=np.uint16)
52
+ labels[2:7, 2:7, 2:7] = 1
53
+
54
+ # Apply morphological smoothing with a radius of 1
55
+ smoothed_labels = nbmorph.smooth_labels_spherical(labels, radius=1)
56
+
57
+ print("Smoothing complete. The smoothed labels are in the 'smoothed_labels' array.")
58
+
59
+ ```
60
+
61
+ ## Operations
62
+
63
+ The core functions of the library are:
64
+
65
+ * `nbmorph.dilate_labels_spherical(labels, radius=1)`
66
+
67
+ * `nbmorph.erode_labels_spherical(labels, radius=1)`
68
+
69
+ * `nbmorph.open_labels_spherical(labels, radius=1, iterations=1)`
70
+
71
+ * `nbmorph.close_labels_spherical(labels, radius=1, iterations=1)`
72
+
73
+ * `nbmorph.smooth_labels_spherical(labels, radius=1, iterations=1)`
74
+
75
+ ## Testing
76
+
77
+ Tests are written using `pytest`. To run the tests, first install the test dependencies and then run `pytest`:
78
+
79
+ ```
80
+ pip install .[test]
81
+ pytest
82
+ ```
83
+
84
+ ## Benchmarking
85
+
86
+ A benchmark script is included in the `scripts` directory:
87
+
88
+ ```
89
+ python scripts/benchmark.py
90
+ ```
91
+
92
+ ## License
93
+
94
+ This project is licensed under the MIT License - see the `LICENSE` file for details.
@@ -0,0 +1,35 @@
1
+ # pyproject.toml
2
+
3
+ [project]
4
+ name = "nbmorph"
5
+ version = "0.1.0"
6
+ authors = [
7
+ { name="Marius Causemann", email="mariusca@simula.no" },
8
+ ]
9
+ description = "A small package with Numba-accelerated morphological operations."
10
+ readme = "README.md"
11
+ license = { file="LICENSE" }
12
+ requires-python = ">=3.8"
13
+ classifiers = [
14
+ "Programming Language :: Python :: 3",
15
+ "License :: OSI Approved :: MIT License",
16
+ "Operating System :: OS Independent",
17
+ "Intended Audience :: Science/Research",
18
+ "Topic :: Scientific/Engineering :: Image Processing",
19
+ ]
20
+ dependencies = [
21
+ "numpy",
22
+ "numba",
23
+ ]
24
+
25
+ [project.optional-dependencies]
26
+ test = [
27
+ "pytest", "pytest-cov", "fastmorph",
28
+ ]
29
+
30
+ [tool.coverage.run]
31
+ branch = false
32
+
33
+ [tool.coverage.report]
34
+ ignore_errors = true
35
+
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,14 @@
1
+ from .morphology import (
2
+ dilate_labels_spherical,
3
+ erode_labels_spherical,
4
+ open_labels_spherical,
5
+ close_labels_spherical,
6
+ smooth_labels_spherical,
7
+ )
8
+ from .mode import onlyzero_mode_box,onlyzero_mode_diamond, fast_mode
9
+ from .minmax import minimum_box, maximum_box, minimum_diamond, maximum_diamond
10
+ from .zero_edges import zero_label_edges_box, zero_label_edges_diamond
11
+ from .utils import cycle
12
+
13
+ # Define the package version
14
+ __version__ = "0.1.0"