numba-morph 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.
Files changed (41) hide show
  1. numba_morph-0.1.0/LICENSE.md +9 -0
  2. numba_morph-0.1.0/PKG-INFO +132 -0
  3. numba_morph-0.1.0/README.md +111 -0
  4. numba_morph-0.1.0/pyproject.toml +36 -0
  5. numba_morph-0.1.0/setup.cfg +4 -0
  6. numba_morph-0.1.0/src/numba_morph/__init__.py +15 -0
  7. numba_morph-0.1.0/src/numba_morph/_chamfer.py +409 -0
  8. numba_morph-0.1.0/src/numba_morph/_edt.py +156 -0
  9. numba_morph-0.1.0/src/numba_morph/_scan.py +696 -0
  10. numba_morph-0.1.0/src/numba_morph/_watershed.py +165 -0
  11. numba_morph-0.1.0/src/numba_morph/cdt.py +82 -0
  12. numba_morph-0.1.0/src/numba_morph/dilation.py +42 -0
  13. numba_morph-0.1.0/src/numba_morph/erosion.py +102 -0
  14. numba_morph-0.1.0/src/numba_morph/fill_holes.py +34 -0
  15. numba_morph-0.1.0/src/numba_morph/gradient.py +50 -0
  16. numba_morph-0.1.0/src/numba_morph/h_min_max.py +156 -0
  17. numba_morph-0.1.0/src/numba_morph/laplace.py +53 -0
  18. numba_morph-0.1.0/src/numba_morph/local_min_max.py +83 -0
  19. numba_morph-0.1.0/src/numba_morph/open_close.py +88 -0
  20. numba_morph-0.1.0/src/numba_morph/reconstruction.py +115 -0
  21. numba_morph-0.1.0/src/numba_morph/reconstruction_old.py +423 -0
  22. numba_morph-0.1.0/src/numba_morph/top_hats.py +89 -0
  23. numba_morph-0.1.0/src/numba_morph/utils.py +111 -0
  24. numba_morph-0.1.0/src/numba_morph/watershed.py +68 -0
  25. numba_morph-0.1.0/src/numba_morph/welford.py +47 -0
  26. numba_morph-0.1.0/src/numba_morph.egg-info/PKG-INFO +132 -0
  27. numba_morph-0.1.0/src/numba_morph.egg-info/SOURCES.txt +39 -0
  28. numba_morph-0.1.0/src/numba_morph.egg-info/dependency_links.txt +1 -0
  29. numba_morph-0.1.0/src/numba_morph.egg-info/requires.txt +4 -0
  30. numba_morph-0.1.0/src/numba_morph.egg-info/top_level.txt +1 -0
  31. numba_morph-0.1.0/tests/test_cdt.py +40 -0
  32. numba_morph-0.1.0/tests/test_dilation.py +64 -0
  33. numba_morph-0.1.0/tests/test_erosion.py +81 -0
  34. numba_morph-0.1.0/tests/test_gradient.py +72 -0
  35. numba_morph-0.1.0/tests/test_h_min_max.py +64 -0
  36. numba_morph-0.1.0/tests/test_laplace.py +72 -0
  37. numba_morph-0.1.0/tests/test_local_min_max.py +76 -0
  38. numba_morph-0.1.0/tests/test_open_close.py +114 -0
  39. numba_morph-0.1.0/tests/test_reconstuction.py +92 -0
  40. numba_morph-0.1.0/tests/test_tophats.py +112 -0
  41. numba_morph-0.1.0/tests/test_watershed.py +49 -0
@@ -0,0 +1,9 @@
1
+
2
+
3
+ Copyright 2026 Yuyao Huang
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
+
7
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
+
9
+ THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,132 @@
1
+ Metadata-Version: 2.4
2
+ Name: numba-morph
3
+ Version: 0.1.0
4
+ Summary: Some image morphology operations optimized with Numba
5
+ Author-email: Yuyao Huang <yuyaoh6@gmail.com>
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/fgdfgfthgr-fox/numba-morph
8
+ Project-URL: Issues, https://github.com/fgdfgfthgr-fox/numba-morph/issues
9
+ Classifier: Programming Language :: Python :: 3
10
+ Classifier: Operating System :: OS Independent
11
+ Classifier: Intended Audience :: Science/Research
12
+ Classifier: Topic :: Scientific/Engineering :: Image Processing
13
+ Requires-Python: >=3.10
14
+ Description-Content-Type: text/markdown
15
+ License-File: LICENSE.md
16
+ Requires-Dist: numpy
17
+ Requires-Dist: numba
18
+ Requires-Dist: scipy
19
+ Requires-Dist: scikit-image
20
+ Dynamic: license-file
21
+
22
+ # numba-morph
23
+
24
+ [![Tests](https://github.com/fgdfgfthgr-fox/numba-morph/actions/workflows/python-app.yml/badge.svg)](https://github.com/fgdfgfthgr-fox/numba-morph/actions/workflows/python-app.yml/badge.svg))
25
+
26
+ A set of Numba-optimised morphological operations.
27
+
28
+ Faster and uses less memory than their scikit-image or SciPy counterpart. Supports batched operations on both 2D and 3D.
29
+
30
+
31
+ ## Features
32
+
33
+ * Numba accelerated: run at native machine code speed!
34
+ * Multi-threading & Batching: Parallelism both within spatial context or across leading dimensions.
35
+ * 2D & 3D with arbitrary leading dimensions.
36
+ * Versatile dtypes: Ops support various integer and float formats natively. There is no internal higher precision dtype.
37
+ * Lower memory use: Avoid padding or creating any unneeded intermediate arrays.
38
+ * All public functions are fully documented.
39
+
40
+ ## List of available functions
41
+
42
+ * dilation, erosion
43
+ * distance_transform_cdt (Chamfer Distance Transform)
44
+ * morphological_gradient
45
+ * h_minima, h_maxima
46
+ * morphological_laplace
47
+ * local_minima, local_maxima *
48
+ * opening, closing
49
+ * reconstruction
50
+ * white_tophat, black_tophat
51
+ * watershed
52
+ * welford_mean_std_w_mask
53
+
54
+ \* Under development, currently only works with integer dtype.
55
+
56
+ ## Installation
57
+ ~~You can install `numba-morph` directly from pypi using pip:~~
58
+ (Still working on it! Give me a few days!)
59
+
60
+ ```
61
+ pip install numba-morph
62
+ ```
63
+
64
+ ## Example
65
+ ```
66
+ import numpy as np
67
+ from numba_morph import dilation
68
+
69
+ original = np.random.randint(0, 8, (32, 64), dtype=np.uint8)
70
+ footprint = ndimage.generate_binary_structure(2, 2)
71
+ result = dilation(original, footprint=footprint)
72
+ ```
73
+
74
+ ## Benchmark
75
+ All testing were done on an AMD Ryzen 7 7735HS CPU.
76
+ You can replicate the result using the benchmark.py.
77
+
78
+ Note: all the time given does not include the start-up time needed for Numba to compile.
79
+ This takes from a fraction of a second to a few seconds, depending on the testing ops.
80
+
81
+ Dilation (int16):
82
+
83
+ | Array Size | Time taken for numba-morph | Time taken for SciPy | Memory use (numba-morph) | Memory use (SciPy) |
84
+ |---------------------------|----------------------------|----------------------|--------------------------|--------------------|
85
+ | 64x64x64 | **0.0072s** | 0.0076s | 0.022GB | **0.001GB** |
86
+ | 128x128x128 | **0.0461s** | 0.1335s | 0.033GB | **0.012GB** |
87
+ | 256x256x256 | **0.3823s** | 2.0027s | 0.12GB | **0.09GB** |
88
+ | 512x512x512 | **2.5800s** | 25.7317s | 0.77GB | **0.75GB** |
89
+ | 256x256 | **0.0006s** | 0.0014s | 0.02GB | **~0.0GB** |
90
+ | 1024x1024 | **0.0101s** | 0.0214s | 0.026GB | **0.006GB** |
91
+ | 4096x4096 | **0.1617s** | 0.5816s | 0.11GB | **0.09GB** |
92
+ | 8x4096x4096 (2D, batched) | **1.0951s** | 4.9948s | 0.77GB | **0.75GB** |
93
+
94
+ Reconstruction (int16):
95
+
96
+ | Array Size | Time taken for numba-morph | Time taken for scikit-image | Memory use (numba-morph) | Memory use (scikit-image) |
97
+ |---------------------------|----------------------------|-----------------------------|--------------------------|---------------------------|
98
+ | 64x64x64 | 0.1343s | **0.1127s** | **0.024GB** | 0.025GB |
99
+ | 128x128x128 | **1.3726s** | 1.8128s | **0.040GB** | 0.192GB |
100
+ | 256x256 | **0.0046s** | 0.0103s | **0.002GB** | 0.006GB |
101
+ | 1024x1024 | **0.0897s** | 0.3546s | **0.029GB** | 0.092GB |
102
+ | 8x64x64x128 (3D, batched) | **1.0468s** | 2.2300s | **0.053GB** | 0.075GB |
103
+ | 8x2048x2048 (2D, batched) | **2.0700s** | 18.5615s | **0.271GB** | 0.571GB |
104
+
105
+ Chamfer Distance Transform (in=uint8, out=int32):
106
+ Note numba-morph don't have time advantage here. It's optimised for memory use.
107
+ Another advantage of numba-morph not showing here is able to specify output directly in other dtype. e.g. smaller uint16
108
+
109
+ | Array Size | Time taken for numba-morph | Time taken for scikit-image | Memory use (numba-morph) | Memory use (scikit-image) |
110
+ |-----------------------------|----------------------------|-----------------------------|--------------------------|---------------------------|
111
+ | 64x64x64 | 0.0123s | **0.0059s** | 0.017GB | **0.004GB** |
112
+ | 256x256x256 | 0.4401s | **0.3687s** | **0.175GB** | 0.266GB |
113
+ | 512x1024x1024 | 10.1897s | **5.9755s** | **2.519GB** | 4.250GB |
114
+ | 512x512 | 0.0058s | **0.0042s** | 0.017GB | **0.004GB** |
115
+ | 4096x4096 | **0.2333s** | 0.2606s | **0.176GB** | 0.266GB |
116
+ | 8x128x128x256 (3D, batched) | **0.5874s** | 1.2909s | **0.328GB** | 0.531GB |
117
+ | 8x4096x4096 (2D, batched) | **1.5051s** | 2.9589s | **1.269GB** | 2.125GB |
118
+
119
+ ## Limitations
120
+ * Does not support float16 inputs, this is due to [an issue with Numba](https://github.com/numba/numba/issues/4402).
121
+ * Speed gain is small or none for smaller inputs.
122
+ * Requires compiling, which means it's going to be slower if your images are small.
123
+
124
+ ## License
125
+
126
+ This project is licensed under the MIT License - see the `LICENSE` file for details.
127
+
128
+ ## AI use disclaimer
129
+
130
+ DeepSeek was used to generate and quality check the functions.
131
+ All functions with AI involvement were manually thoroughly analysed,
132
+ tested with data, modified and verified to satisfy desired input and output conditions.
@@ -0,0 +1,111 @@
1
+ # numba-morph
2
+
3
+ [![Tests](https://github.com/fgdfgfthgr-fox/numba-morph/actions/workflows/python-app.yml/badge.svg)](https://github.com/fgdfgfthgr-fox/numba-morph/actions/workflows/python-app.yml/badge.svg))
4
+
5
+ A set of Numba-optimised morphological operations.
6
+
7
+ Faster and uses less memory than their scikit-image or SciPy counterpart. Supports batched operations on both 2D and 3D.
8
+
9
+
10
+ ## Features
11
+
12
+ * Numba accelerated: run at native machine code speed!
13
+ * Multi-threading & Batching: Parallelism both within spatial context or across leading dimensions.
14
+ * 2D & 3D with arbitrary leading dimensions.
15
+ * Versatile dtypes: Ops support various integer and float formats natively. There is no internal higher precision dtype.
16
+ * Lower memory use: Avoid padding or creating any unneeded intermediate arrays.
17
+ * All public functions are fully documented.
18
+
19
+ ## List of available functions
20
+
21
+ * dilation, erosion
22
+ * distance_transform_cdt (Chamfer Distance Transform)
23
+ * morphological_gradient
24
+ * h_minima, h_maxima
25
+ * morphological_laplace
26
+ * local_minima, local_maxima *
27
+ * opening, closing
28
+ * reconstruction
29
+ * white_tophat, black_tophat
30
+ * watershed
31
+ * welford_mean_std_w_mask
32
+
33
+ \* Under development, currently only works with integer dtype.
34
+
35
+ ## Installation
36
+ ~~You can install `numba-morph` directly from pypi using pip:~~
37
+ (Still working on it! Give me a few days!)
38
+
39
+ ```
40
+ pip install numba-morph
41
+ ```
42
+
43
+ ## Example
44
+ ```
45
+ import numpy as np
46
+ from numba_morph import dilation
47
+
48
+ original = np.random.randint(0, 8, (32, 64), dtype=np.uint8)
49
+ footprint = ndimage.generate_binary_structure(2, 2)
50
+ result = dilation(original, footprint=footprint)
51
+ ```
52
+
53
+ ## Benchmark
54
+ All testing were done on an AMD Ryzen 7 7735HS CPU.
55
+ You can replicate the result using the benchmark.py.
56
+
57
+ Note: all the time given does not include the start-up time needed for Numba to compile.
58
+ This takes from a fraction of a second to a few seconds, depending on the testing ops.
59
+
60
+ Dilation (int16):
61
+
62
+ | Array Size | Time taken for numba-morph | Time taken for SciPy | Memory use (numba-morph) | Memory use (SciPy) |
63
+ |---------------------------|----------------------------|----------------------|--------------------------|--------------------|
64
+ | 64x64x64 | **0.0072s** | 0.0076s | 0.022GB | **0.001GB** |
65
+ | 128x128x128 | **0.0461s** | 0.1335s | 0.033GB | **0.012GB** |
66
+ | 256x256x256 | **0.3823s** | 2.0027s | 0.12GB | **0.09GB** |
67
+ | 512x512x512 | **2.5800s** | 25.7317s | 0.77GB | **0.75GB** |
68
+ | 256x256 | **0.0006s** | 0.0014s | 0.02GB | **~0.0GB** |
69
+ | 1024x1024 | **0.0101s** | 0.0214s | 0.026GB | **0.006GB** |
70
+ | 4096x4096 | **0.1617s** | 0.5816s | 0.11GB | **0.09GB** |
71
+ | 8x4096x4096 (2D, batched) | **1.0951s** | 4.9948s | 0.77GB | **0.75GB** |
72
+
73
+ Reconstruction (int16):
74
+
75
+ | Array Size | Time taken for numba-morph | Time taken for scikit-image | Memory use (numba-morph) | Memory use (scikit-image) |
76
+ |---------------------------|----------------------------|-----------------------------|--------------------------|---------------------------|
77
+ | 64x64x64 | 0.1343s | **0.1127s** | **0.024GB** | 0.025GB |
78
+ | 128x128x128 | **1.3726s** | 1.8128s | **0.040GB** | 0.192GB |
79
+ | 256x256 | **0.0046s** | 0.0103s | **0.002GB** | 0.006GB |
80
+ | 1024x1024 | **0.0897s** | 0.3546s | **0.029GB** | 0.092GB |
81
+ | 8x64x64x128 (3D, batched) | **1.0468s** | 2.2300s | **0.053GB** | 0.075GB |
82
+ | 8x2048x2048 (2D, batched) | **2.0700s** | 18.5615s | **0.271GB** | 0.571GB |
83
+
84
+ Chamfer Distance Transform (in=uint8, out=int32):
85
+ Note numba-morph don't have time advantage here. It's optimised for memory use.
86
+ Another advantage of numba-morph not showing here is able to specify output directly in other dtype. e.g. smaller uint16
87
+
88
+ | Array Size | Time taken for numba-morph | Time taken for scikit-image | Memory use (numba-morph) | Memory use (scikit-image) |
89
+ |-----------------------------|----------------------------|-----------------------------|--------------------------|---------------------------|
90
+ | 64x64x64 | 0.0123s | **0.0059s** | 0.017GB | **0.004GB** |
91
+ | 256x256x256 | 0.4401s | **0.3687s** | **0.175GB** | 0.266GB |
92
+ | 512x1024x1024 | 10.1897s | **5.9755s** | **2.519GB** | 4.250GB |
93
+ | 512x512 | 0.0058s | **0.0042s** | 0.017GB | **0.004GB** |
94
+ | 4096x4096 | **0.2333s** | 0.2606s | **0.176GB** | 0.266GB |
95
+ | 8x128x128x256 (3D, batched) | **0.5874s** | 1.2909s | **0.328GB** | 0.531GB |
96
+ | 8x4096x4096 (2D, batched) | **1.5051s** | 2.9589s | **1.269GB** | 2.125GB |
97
+
98
+ ## Limitations
99
+ * Does not support float16 inputs, this is due to [an issue with Numba](https://github.com/numba/numba/issues/4402).
100
+ * Speed gain is small or none for smaller inputs.
101
+ * Requires compiling, which means it's going to be slower if your images are small.
102
+
103
+ ## License
104
+
105
+ This project is licensed under the MIT License - see the `LICENSE` file for details.
106
+
107
+ ## AI use disclaimer
108
+
109
+ DeepSeek was used to generate and quality check the functions.
110
+ All functions with AI involvement were manually thoroughly analysed,
111
+ tested with data, modified and verified to satisfy desired input and output conditions.
@@ -0,0 +1,36 @@
1
+ [build-system]
2
+ requires = ["setuptools >= 77.0.3"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [tool.setuptools.packages.find]
6
+ where = ["src"]
7
+ include = ["numba_morph*"] # Use underscore here
8
+ exclude = ["tests*"]
9
+
10
+ [project]
11
+ name = "numba-morph"
12
+ version = "0.1.0"
13
+ authors = [
14
+ { name="Yuyao Huang", email="yuyaoh6@gmail.com" },
15
+ ]
16
+ description = "Some image morphology operations optimized with Numba"
17
+ readme = "README.md"
18
+ requires-python = ">=3.10"
19
+ classifiers = [
20
+ "Programming Language :: Python :: 3",
21
+ "Operating System :: OS Independent",
22
+ "Intended Audience :: Science/Research",
23
+ "Topic :: Scientific/Engineering :: Image Processing",
24
+ ]
25
+ dependencies = [
26
+ "numpy",
27
+ "numba",
28
+ "scipy",
29
+ "scikit-image"
30
+ ]
31
+ license = "MIT"
32
+ license-files = ["LICEN[CS]E*"]
33
+
34
+ [project.urls]
35
+ Homepage = "https://github.com/fgdfgfthgr-fox/numba-morph"
36
+ Issues = "https://github.com/fgdfgfthgr-fox/numba-morph/issues"
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,15 @@
1
+ __version__ = "0.1.0"
2
+
3
+ from .cdt import distance_transform_cdt
4
+ from .dilation import dilation
5
+ from .erosion import erosion
6
+ from .gradient import morphological_gradient
7
+ from .h_min_max import h_minima, h_maxima
8
+ from .laplace import morphological_laplace
9
+ from .local_min_max import local_minima, local_maxima
10
+ from .open_close import opening, closing
11
+ from .reconstruction import reconstruction
12
+ from .top_hats import white_tophat, black_tophat
13
+ from .utils import generate_sphere_structure
14
+ from .watershed import watershed
15
+ from .welford import welford_mean_std_w_mask