albucore 0.0.1__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.
- albucore-0.0.1/LICENSE +21 -0
- albucore-0.0.1/PKG-INFO +93 -0
- albucore-0.0.1/README.md +61 -0
- albucore-0.0.1/albucore/__init__.py +3 -0
- albucore-0.0.1/albucore/functions.py +58 -0
- albucore-0.0.1/albucore/utils.py +119 -0
- albucore-0.0.1/albucore.egg-info/PKG-INFO +93 -0
- albucore-0.0.1/albucore.egg-info/SOURCES.txt +14 -0
- albucore-0.0.1/albucore.egg-info/dependency_links.txt +1 -0
- albucore-0.0.1/albucore.egg-info/not-zip-safe +1 -0
- albucore-0.0.1/albucore.egg-info/requires.txt +3 -0
- albucore-0.0.1/albucore.egg-info/top_level.txt +1 -0
- albucore-0.0.1/pyproject.toml +176 -0
- albucore-0.0.1/setup.cfg +4 -0
- albucore-0.0.1/setup.py +89 -0
- albucore-0.0.1/tests/test_functions.py +38 -0
albucore-0.0.1/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Vladimir Iglovikov
|
|
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.
|
albucore-0.0.1/PKG-INFO
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: albucore
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Summary: A high-performance image processing library designed to optimize and extend the Albumentations library with specialized functions for advanced image transformations. Perfect for developers working in computer vision who require efficient and scalable image augmentation.
|
|
5
|
+
Home-page: https://github.com/albumentations-team/albucore
|
|
6
|
+
Author: Vladimir I. Iglovikov
|
|
7
|
+
License: MIT
|
|
8
|
+
Keywords: Image Processing,Computer Vision,Image Augmentation,Albumentations,Optimization,Machine Learning,Deep Learning,Python Imaging,Data Augmentation,Performance,Efficiency,High-Performance,CV,OpenCV,Automation
|
|
9
|
+
Classifier: Development Status :: 4 - Beta
|
|
10
|
+
Classifier: Intended Audience :: Developers
|
|
11
|
+
Classifier: Intended Audience :: Science/Research
|
|
12
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
13
|
+
Classifier: Operating System :: OS Independent
|
|
14
|
+
Classifier: Programming Language :: Python
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
21
|
+
Classifier: Topic :: Software Development :: Libraries
|
|
22
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
23
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
24
|
+
Classifier: Topic :: Scientific/Engineering :: Image Processing
|
|
25
|
+
Classifier: Typing :: Typed
|
|
26
|
+
Requires-Python: >=3.8
|
|
27
|
+
Description-Content-Type: text/markdown
|
|
28
|
+
License-File: LICENSE
|
|
29
|
+
Requires-Dist: numpy>=1.24.4
|
|
30
|
+
Requires-Dist: tomli>=2.0.1
|
|
31
|
+
Requires-Dist: opencv-python-headless>=4.9.0
|
|
32
|
+
|
|
33
|
+
# Albucore
|
|
34
|
+
|
|
35
|
+
Albucore is a high-performance image processing library designed to optimize operations on images using Python and OpenCV, building upon the foundations laid by the popular Albumentations library. It offers specialized optimizations for different image data types and aims to provide faster processing times through efficient algorithm implementations.
|
|
36
|
+
|
|
37
|
+
## Features
|
|
38
|
+
|
|
39
|
+
- Optimized image multiplication operations for both `uint8` and `float32` data types.
|
|
40
|
+
- Support for single-channel and multi-channel images.
|
|
41
|
+
- Custom decorators to manage channel dimensions and output constraints.
|
|
42
|
+
|
|
43
|
+
## Installation
|
|
44
|
+
|
|
45
|
+
Install Albucore using pip:
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
pip install -U albucore
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## Example
|
|
52
|
+
|
|
53
|
+
Here's how you can use Albucore to multiply an image by a constant or a vector:
|
|
54
|
+
|
|
55
|
+
```python
|
|
56
|
+
import cv2
|
|
57
|
+
import numpy as np
|
|
58
|
+
from albucore import multiply
|
|
59
|
+
|
|
60
|
+
# Load an image
|
|
61
|
+
img = cv2.imread('path_to_your_image.jpg')
|
|
62
|
+
|
|
63
|
+
# Multiply by a constant
|
|
64
|
+
multiplied_image = multiply(img, 1.5)
|
|
65
|
+
|
|
66
|
+
# Multiply by a vector
|
|
67
|
+
multiplier = [1.5, 1.2, 0.9] # Different multiplier for each channel
|
|
68
|
+
multiplied_image = multiply(img, multiplier)
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
## Benchmarks
|
|
72
|
+
|
|
73
|
+
### Benchmark Results for 1000 Images of `float32` Type (256, 256, 1)
|
|
74
|
+
|
|
75
|
+
| | albucore | opencv | numpy |
|
|
76
|
+
| ---------------- | ------------ | ---------------- | ---------------- |
|
|
77
|
+
| MultiplyConstant | 12925 ± 1237 | 10963 ± 1053 | **14040 ± 2063** |
|
|
78
|
+
| MultiplyVector | 3832 ± 512 | **10824 ± 1005** | 8986 ± 511 |
|
|
79
|
+
|
|
80
|
+
### Benchmark Results for 1000 Images of `uint8` Type (256, 256, 1)
|
|
81
|
+
|
|
82
|
+
| | albucore | opencv | numpy |
|
|
83
|
+
| ---------------- | ---------------- | ----------- | ---------- |
|
|
84
|
+
| MultiplyConstant | **24131 ± 1129** | 11622 ± 175 | 6969 ± 643 |
|
|
85
|
+
| MultiplyVector | **24279 ± 908** | 11756 ± 152 | 6936 ± 408 |
|
|
86
|
+
|
|
87
|
+
Albucore provides significant performance improvements for image processing tasks. Here are some benchmark results comparing Albucore with OpenCV and Numpy:
|
|
88
|
+
|
|
89
|
+
For more detailed benchmark results, including other configurations and data types, refer to the [Benchmark.md](Benchmark.md) in the repository.
|
|
90
|
+
|
|
91
|
+
## License
|
|
92
|
+
|
|
93
|
+
Distributed under the MIT License. See LICENSE for more information.
|
albucore-0.0.1/README.md
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
# Albucore
|
|
2
|
+
|
|
3
|
+
Albucore is a high-performance image processing library designed to optimize operations on images using Python and OpenCV, building upon the foundations laid by the popular Albumentations library. It offers specialized optimizations for different image data types and aims to provide faster processing times through efficient algorithm implementations.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- Optimized image multiplication operations for both `uint8` and `float32` data types.
|
|
8
|
+
- Support for single-channel and multi-channel images.
|
|
9
|
+
- Custom decorators to manage channel dimensions and output constraints.
|
|
10
|
+
|
|
11
|
+
## Installation
|
|
12
|
+
|
|
13
|
+
Install Albucore using pip:
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
pip install -U albucore
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Example
|
|
20
|
+
|
|
21
|
+
Here's how you can use Albucore to multiply an image by a constant or a vector:
|
|
22
|
+
|
|
23
|
+
```python
|
|
24
|
+
import cv2
|
|
25
|
+
import numpy as np
|
|
26
|
+
from albucore import multiply
|
|
27
|
+
|
|
28
|
+
# Load an image
|
|
29
|
+
img = cv2.imread('path_to_your_image.jpg')
|
|
30
|
+
|
|
31
|
+
# Multiply by a constant
|
|
32
|
+
multiplied_image = multiply(img, 1.5)
|
|
33
|
+
|
|
34
|
+
# Multiply by a vector
|
|
35
|
+
multiplier = [1.5, 1.2, 0.9] # Different multiplier for each channel
|
|
36
|
+
multiplied_image = multiply(img, multiplier)
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## Benchmarks
|
|
40
|
+
|
|
41
|
+
### Benchmark Results for 1000 Images of `float32` Type (256, 256, 1)
|
|
42
|
+
|
|
43
|
+
| | albucore | opencv | numpy |
|
|
44
|
+
| ---------------- | ------------ | ---------------- | ---------------- |
|
|
45
|
+
| MultiplyConstant | 12925 ± 1237 | 10963 ± 1053 | **14040 ± 2063** |
|
|
46
|
+
| MultiplyVector | 3832 ± 512 | **10824 ± 1005** | 8986 ± 511 |
|
|
47
|
+
|
|
48
|
+
### Benchmark Results for 1000 Images of `uint8` Type (256, 256, 1)
|
|
49
|
+
|
|
50
|
+
| | albucore | opencv | numpy |
|
|
51
|
+
| ---------------- | ---------------- | ----------- | ---------- |
|
|
52
|
+
| MultiplyConstant | **24131 ± 1129** | 11622 ± 175 | 6969 ± 643 |
|
|
53
|
+
| MultiplyVector | **24279 ± 908** | 11756 ± 152 | 6936 ± 408 |
|
|
54
|
+
|
|
55
|
+
Albucore provides significant performance improvements for image processing tasks. Here are some benchmark results comparing Albucore with OpenCV and Numpy:
|
|
56
|
+
|
|
57
|
+
For more detailed benchmark results, including other configurations and data types, refer to the [Benchmark.md](Benchmark.md) in the repository.
|
|
58
|
+
|
|
59
|
+
## License
|
|
60
|
+
|
|
61
|
+
Distributed under the MIT License. See LICENSE for more information.
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
from typing import Sequence, Union
|
|
2
|
+
|
|
3
|
+
import cv2
|
|
4
|
+
import numpy as np
|
|
5
|
+
|
|
6
|
+
from albucore.utils import (
|
|
7
|
+
MAX_VALUES_BY_DTYPE,
|
|
8
|
+
clip,
|
|
9
|
+
clipped,
|
|
10
|
+
is_grayscale_image,
|
|
11
|
+
maybe_process_in_chunks,
|
|
12
|
+
preserve_channel_dim,
|
|
13
|
+
)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
@clipped
|
|
17
|
+
def _multiply_non_uint8_optimized(img: np.ndarray, multiplier: Union[Sequence[float], float]) -> np.ndarray:
|
|
18
|
+
img = img.astype(np.float32)
|
|
19
|
+
return np.multiply(img, multiplier)
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
@preserve_channel_dim
|
|
23
|
+
def _multiply_uint8_optimized(img: np.ndarray, multiplier: Union[Sequence[float], float]) -> np.ndarray:
|
|
24
|
+
max_value = MAX_VALUES_BY_DTYPE[np.uint8]
|
|
25
|
+
if isinstance(multiplier, float):
|
|
26
|
+
lut = np.arange(0, max_value + 1, dtype=np.float32)
|
|
27
|
+
lut *= multiplier
|
|
28
|
+
lut = clip(lut, np.uint8)
|
|
29
|
+
func = maybe_process_in_chunks(cv2.LUT, lut=lut)
|
|
30
|
+
return func(img)
|
|
31
|
+
|
|
32
|
+
if is_grayscale_image(img):
|
|
33
|
+
multiplier = multiplier[0]
|
|
34
|
+
lut = np.arange(0, max_value + 1, dtype=np.float32)
|
|
35
|
+
lut *= multiplier
|
|
36
|
+
lut = clip(lut, np.uint8)
|
|
37
|
+
func = maybe_process_in_chunks(cv2.LUT, lut=lut)
|
|
38
|
+
return func(img)
|
|
39
|
+
|
|
40
|
+
num_channels = img.shape[-1]
|
|
41
|
+
lut = [np.arange(0, max_value + 1, dtype=np.float32)] * num_channels
|
|
42
|
+
lut = np.stack(lut, axis=-1)
|
|
43
|
+
|
|
44
|
+
lut *= multiplier
|
|
45
|
+
lut = clip(lut, np.uint8)
|
|
46
|
+
|
|
47
|
+
images = []
|
|
48
|
+
for i in range(num_channels):
|
|
49
|
+
func = maybe_process_in_chunks(cv2.LUT, lut=lut[:, i])
|
|
50
|
+
images.append(func(img[:, :, i]))
|
|
51
|
+
return np.stack(images, axis=-1)
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def multiply(img: np.ndarray, multiplier: Union[Sequence[float], float]) -> np.ndarray:
|
|
55
|
+
if img.dtype == np.uint8:
|
|
56
|
+
return _multiply_uint8_optimized(img, multiplier)
|
|
57
|
+
|
|
58
|
+
return _multiply_non_uint8_optimized(img, multiplier)
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
from functools import wraps
|
|
2
|
+
from typing import Any, Callable
|
|
3
|
+
|
|
4
|
+
import cv2
|
|
5
|
+
import numpy as np
|
|
6
|
+
from typing_extensions import Concatenate, ParamSpec
|
|
7
|
+
|
|
8
|
+
MONO_CHANNEL_DIMENSIONS = 2
|
|
9
|
+
NUM_MULTI_CHANNEL_DIMENSIONS = 3
|
|
10
|
+
FOUR = 4
|
|
11
|
+
TWO = 2
|
|
12
|
+
|
|
13
|
+
P = ParamSpec("P")
|
|
14
|
+
|
|
15
|
+
MAX_VALUES_BY_DTYPE = {
|
|
16
|
+
np.dtype("uint8"): 255,
|
|
17
|
+
np.dtype("uint16"): 65535,
|
|
18
|
+
np.dtype("uint32"): 4294967295,
|
|
19
|
+
np.dtype("float32"): 1.0,
|
|
20
|
+
np.uint8: 255,
|
|
21
|
+
np.uint16: 65535,
|
|
22
|
+
np.uint32: 4294967295,
|
|
23
|
+
np.float32: 1.0,
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
NPDTYPE_TO_OPENCV_DTYPE = {
|
|
27
|
+
np.uint8: cv2.CV_8U,
|
|
28
|
+
np.uint16: cv2.CV_16U,
|
|
29
|
+
np.int32: cv2.CV_32S,
|
|
30
|
+
np.float32: cv2.CV_32F,
|
|
31
|
+
np.float64: cv2.CV_64F,
|
|
32
|
+
np.dtype("uint8"): cv2.CV_8U,
|
|
33
|
+
np.dtype("uint16"): cv2.CV_16U,
|
|
34
|
+
np.dtype("int32"): cv2.CV_32S,
|
|
35
|
+
np.dtype("float32"): cv2.CV_32F,
|
|
36
|
+
np.dtype("float64"): cv2.CV_64F,
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def maybe_process_in_chunks(
|
|
41
|
+
process_fn: Callable[Concatenate[np.ndarray, P], np.ndarray], **kwargs: Any
|
|
42
|
+
) -> Callable[[np.ndarray], np.ndarray]:
|
|
43
|
+
"""Wrap OpenCV function to enable processing images with more than 4 channels.
|
|
44
|
+
|
|
45
|
+
Limitations:
|
|
46
|
+
This wrapper requires image to be the first argument and rest must be sent via named arguments.
|
|
47
|
+
|
|
48
|
+
Args:
|
|
49
|
+
process_fn: Transform function (e.g cv2.resize).
|
|
50
|
+
kwargs: Additional parameters.
|
|
51
|
+
|
|
52
|
+
Returns:
|
|
53
|
+
np.ndarray: Transformed image.
|
|
54
|
+
|
|
55
|
+
"""
|
|
56
|
+
|
|
57
|
+
@wraps(process_fn)
|
|
58
|
+
def __process_fn(img: np.ndarray) -> np.ndarray:
|
|
59
|
+
num_channels = get_num_channels(img)
|
|
60
|
+
if num_channels > FOUR:
|
|
61
|
+
chunks = []
|
|
62
|
+
for index in range(0, num_channels, 4):
|
|
63
|
+
if num_channels - index == TWO:
|
|
64
|
+
# Many OpenCV functions cannot work with 2-channel images
|
|
65
|
+
for i in range(2):
|
|
66
|
+
chunk = img[:, :, index + i : index + i + 1]
|
|
67
|
+
chunk = process_fn(chunk, **kwargs)
|
|
68
|
+
chunk = np.expand_dims(chunk, -1)
|
|
69
|
+
chunks.append(chunk)
|
|
70
|
+
else:
|
|
71
|
+
chunk = img[:, :, index : index + 4]
|
|
72
|
+
chunk = process_fn(chunk, **kwargs)
|
|
73
|
+
chunks.append(chunk)
|
|
74
|
+
return np.dstack(chunks)
|
|
75
|
+
|
|
76
|
+
return process_fn(img, **kwargs)
|
|
77
|
+
|
|
78
|
+
return __process_fn
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
def clip(img: np.ndarray, dtype: Any) -> np.ndarray:
|
|
82
|
+
max_value = MAX_VALUES_BY_DTYPE[dtype]
|
|
83
|
+
return np.clip(img, 0, max_value).astype(dtype)
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
def clipped(func: Callable[Concatenate[np.ndarray, P], np.ndarray]) -> Callable[Concatenate[np.ndarray, P], np.ndarray]:
|
|
87
|
+
@wraps(func)
|
|
88
|
+
def wrapped_function(img: np.ndarray, *args: P.args, **kwargs: P.kwargs) -> np.ndarray:
|
|
89
|
+
dtype = img.dtype
|
|
90
|
+
return clip(func(img, *args, **kwargs), dtype)
|
|
91
|
+
|
|
92
|
+
return wrapped_function
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
def get_num_channels(image: np.ndarray) -> int:
|
|
96
|
+
return image.shape[2] if image.ndim == NUM_MULTI_CHANNEL_DIMENSIONS else 1
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
def preserve_channel_dim(
|
|
100
|
+
func: Callable[Concatenate[np.ndarray, P], np.ndarray],
|
|
101
|
+
) -> Callable[Concatenate[np.ndarray, P], np.ndarray]:
|
|
102
|
+
"""Preserve dummy channel dim."""
|
|
103
|
+
|
|
104
|
+
@wraps(func)
|
|
105
|
+
def wrapped_function(img: np.ndarray, *args: P.args, **kwargs: P.kwargs) -> np.ndarray:
|
|
106
|
+
shape = img.shape
|
|
107
|
+
result = func(img, *args, **kwargs)
|
|
108
|
+
if len(shape) == NUM_MULTI_CHANNEL_DIMENSIONS and shape[-1] == 1 and result.ndim == MONO_CHANNEL_DIMENSIONS:
|
|
109
|
+
return np.expand_dims(result, axis=-1)
|
|
110
|
+
|
|
111
|
+
if len(shape) == MONO_CHANNEL_DIMENSIONS and result.ndim == NUM_MULTI_CHANNEL_DIMENSIONS:
|
|
112
|
+
return result[:, :, 0]
|
|
113
|
+
return result
|
|
114
|
+
|
|
115
|
+
return wrapped_function
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
def is_grayscale_image(image: np.ndarray) -> bool:
|
|
119
|
+
return get_num_channels(image) == 1
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: albucore
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Summary: A high-performance image processing library designed to optimize and extend the Albumentations library with specialized functions for advanced image transformations. Perfect for developers working in computer vision who require efficient and scalable image augmentation.
|
|
5
|
+
Home-page: https://github.com/albumentations-team/albucore
|
|
6
|
+
Author: Vladimir I. Iglovikov
|
|
7
|
+
License: MIT
|
|
8
|
+
Keywords: Image Processing,Computer Vision,Image Augmentation,Albumentations,Optimization,Machine Learning,Deep Learning,Python Imaging,Data Augmentation,Performance,Efficiency,High-Performance,CV,OpenCV,Automation
|
|
9
|
+
Classifier: Development Status :: 4 - Beta
|
|
10
|
+
Classifier: Intended Audience :: Developers
|
|
11
|
+
Classifier: Intended Audience :: Science/Research
|
|
12
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
13
|
+
Classifier: Operating System :: OS Independent
|
|
14
|
+
Classifier: Programming Language :: Python
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
21
|
+
Classifier: Topic :: Software Development :: Libraries
|
|
22
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
23
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
24
|
+
Classifier: Topic :: Scientific/Engineering :: Image Processing
|
|
25
|
+
Classifier: Typing :: Typed
|
|
26
|
+
Requires-Python: >=3.8
|
|
27
|
+
Description-Content-Type: text/markdown
|
|
28
|
+
License-File: LICENSE
|
|
29
|
+
Requires-Dist: numpy>=1.24.4
|
|
30
|
+
Requires-Dist: tomli>=2.0.1
|
|
31
|
+
Requires-Dist: opencv-python-headless>=4.9.0
|
|
32
|
+
|
|
33
|
+
# Albucore
|
|
34
|
+
|
|
35
|
+
Albucore is a high-performance image processing library designed to optimize operations on images using Python and OpenCV, building upon the foundations laid by the popular Albumentations library. It offers specialized optimizations for different image data types and aims to provide faster processing times through efficient algorithm implementations.
|
|
36
|
+
|
|
37
|
+
## Features
|
|
38
|
+
|
|
39
|
+
- Optimized image multiplication operations for both `uint8` and `float32` data types.
|
|
40
|
+
- Support for single-channel and multi-channel images.
|
|
41
|
+
- Custom decorators to manage channel dimensions and output constraints.
|
|
42
|
+
|
|
43
|
+
## Installation
|
|
44
|
+
|
|
45
|
+
Install Albucore using pip:
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
pip install -U albucore
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## Example
|
|
52
|
+
|
|
53
|
+
Here's how you can use Albucore to multiply an image by a constant or a vector:
|
|
54
|
+
|
|
55
|
+
```python
|
|
56
|
+
import cv2
|
|
57
|
+
import numpy as np
|
|
58
|
+
from albucore import multiply
|
|
59
|
+
|
|
60
|
+
# Load an image
|
|
61
|
+
img = cv2.imread('path_to_your_image.jpg')
|
|
62
|
+
|
|
63
|
+
# Multiply by a constant
|
|
64
|
+
multiplied_image = multiply(img, 1.5)
|
|
65
|
+
|
|
66
|
+
# Multiply by a vector
|
|
67
|
+
multiplier = [1.5, 1.2, 0.9] # Different multiplier for each channel
|
|
68
|
+
multiplied_image = multiply(img, multiplier)
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
## Benchmarks
|
|
72
|
+
|
|
73
|
+
### Benchmark Results for 1000 Images of `float32` Type (256, 256, 1)
|
|
74
|
+
|
|
75
|
+
| | albucore | opencv | numpy |
|
|
76
|
+
| ---------------- | ------------ | ---------------- | ---------------- |
|
|
77
|
+
| MultiplyConstant | 12925 ± 1237 | 10963 ± 1053 | **14040 ± 2063** |
|
|
78
|
+
| MultiplyVector | 3832 ± 512 | **10824 ± 1005** | 8986 ± 511 |
|
|
79
|
+
|
|
80
|
+
### Benchmark Results for 1000 Images of `uint8` Type (256, 256, 1)
|
|
81
|
+
|
|
82
|
+
| | albucore | opencv | numpy |
|
|
83
|
+
| ---------------- | ---------------- | ----------- | ---------- |
|
|
84
|
+
| MultiplyConstant | **24131 ± 1129** | 11622 ± 175 | 6969 ± 643 |
|
|
85
|
+
| MultiplyVector | **24279 ± 908** | 11756 ± 152 | 6936 ± 408 |
|
|
86
|
+
|
|
87
|
+
Albucore provides significant performance improvements for image processing tasks. Here are some benchmark results comparing Albucore with OpenCV and Numpy:
|
|
88
|
+
|
|
89
|
+
For more detailed benchmark results, including other configurations and data types, refer to the [Benchmark.md](Benchmark.md) in the repository.
|
|
90
|
+
|
|
91
|
+
## License
|
|
92
|
+
|
|
93
|
+
Distributed under the MIT License. See LICENSE for more information.
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
README.md
|
|
3
|
+
pyproject.toml
|
|
4
|
+
setup.py
|
|
5
|
+
albucore/__init__.py
|
|
6
|
+
albucore/functions.py
|
|
7
|
+
albucore/utils.py
|
|
8
|
+
albucore.egg-info/PKG-INFO
|
|
9
|
+
albucore.egg-info/SOURCES.txt
|
|
10
|
+
albucore.egg-info/dependency_links.txt
|
|
11
|
+
albucore.egg-info/not-zip-safe
|
|
12
|
+
albucore.egg-info/requires.txt
|
|
13
|
+
albucore.egg-info/top_level.txt
|
|
14
|
+
tests/test_functions.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
albucore
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
# NOTE: you have to use single-quoted strings in TOML for regular expressions.
|
|
2
|
+
# It's the equivalent of r-strings in Python. Multiline strings are treated as
|
|
3
|
+
# verbose regular expressions by Black. Use [ ] to denote a significant space
|
|
4
|
+
# character.
|
|
5
|
+
|
|
6
|
+
[build-system]
|
|
7
|
+
build-backend = "setuptools.build_meta"
|
|
8
|
+
requires = [
|
|
9
|
+
"setuptools",
|
|
10
|
+
"wheel",
|
|
11
|
+
]
|
|
12
|
+
|
|
13
|
+
[tool.ruff]
|
|
14
|
+
# Exclude a variety of commonly ignored directories.
|
|
15
|
+
exclude = [
|
|
16
|
+
".bzr",
|
|
17
|
+
".direnv",
|
|
18
|
+
".eggs",
|
|
19
|
+
".git",
|
|
20
|
+
".git-rewrite",
|
|
21
|
+
".hg",
|
|
22
|
+
".ipynb_checkpoints",
|
|
23
|
+
".mypy_cache",
|
|
24
|
+
".nox",
|
|
25
|
+
".pants.d",
|
|
26
|
+
".pyenv",
|
|
27
|
+
".pytest_cache",
|
|
28
|
+
".pytype",
|
|
29
|
+
".ruff_cache",
|
|
30
|
+
".svn",
|
|
31
|
+
".tox",
|
|
32
|
+
".venv",
|
|
33
|
+
".vscode",
|
|
34
|
+
"__pypackages__",
|
|
35
|
+
"_build",
|
|
36
|
+
"buck-out",
|
|
37
|
+
"build",
|
|
38
|
+
"dist",
|
|
39
|
+
"node_modules",
|
|
40
|
+
"site-packages",
|
|
41
|
+
"venv",
|
|
42
|
+
"tests",
|
|
43
|
+
"setup.py",
|
|
44
|
+
"tools",
|
|
45
|
+
"site",
|
|
46
|
+
]
|
|
47
|
+
|
|
48
|
+
line-length = 120
|
|
49
|
+
indent-width = 4
|
|
50
|
+
|
|
51
|
+
# Assume Python 3.8
|
|
52
|
+
target-version = "py38"
|
|
53
|
+
|
|
54
|
+
[tool.ruff.lint]
|
|
55
|
+
explicit-preview-rules = true
|
|
56
|
+
|
|
57
|
+
select = [
|
|
58
|
+
"F",
|
|
59
|
+
"E",
|
|
60
|
+
"W",
|
|
61
|
+
"C90",
|
|
62
|
+
"I",
|
|
63
|
+
"N",
|
|
64
|
+
"D",
|
|
65
|
+
"UP",
|
|
66
|
+
"YTT",
|
|
67
|
+
"ANN",
|
|
68
|
+
"ASYNC",
|
|
69
|
+
"TRIO",
|
|
70
|
+
"S",
|
|
71
|
+
"BLE",
|
|
72
|
+
"FBT",
|
|
73
|
+
"B",
|
|
74
|
+
"A",
|
|
75
|
+
"COM",
|
|
76
|
+
"CPY",
|
|
77
|
+
"C4",
|
|
78
|
+
"DTZ",
|
|
79
|
+
"T10",
|
|
80
|
+
"DJ",
|
|
81
|
+
"EM",
|
|
82
|
+
"EXE",
|
|
83
|
+
"ISC",
|
|
84
|
+
"ICN",
|
|
85
|
+
"G",
|
|
86
|
+
"INP",
|
|
87
|
+
"PIE",
|
|
88
|
+
"T20",
|
|
89
|
+
"PYI",
|
|
90
|
+
"PT",
|
|
91
|
+
"Q",
|
|
92
|
+
"RSE",
|
|
93
|
+
"RET",
|
|
94
|
+
"SLF",
|
|
95
|
+
"SLOT",
|
|
96
|
+
"SIM",
|
|
97
|
+
"TID",
|
|
98
|
+
"TCH",
|
|
99
|
+
"INT",
|
|
100
|
+
"ARG",
|
|
101
|
+
"PTH",
|
|
102
|
+
"TD",
|
|
103
|
+
"FIX",
|
|
104
|
+
"ERA",
|
|
105
|
+
"PD",
|
|
106
|
+
"PGH",
|
|
107
|
+
"PL",
|
|
108
|
+
"TRY",
|
|
109
|
+
"FLY",
|
|
110
|
+
"NPY",
|
|
111
|
+
"PERF",
|
|
112
|
+
"FURB",
|
|
113
|
+
"LOG",
|
|
114
|
+
"RUF",
|
|
115
|
+
]
|
|
116
|
+
ignore = [
|
|
117
|
+
"D104",
|
|
118
|
+
"F403",
|
|
119
|
+
"D100",
|
|
120
|
+
"D103",
|
|
121
|
+
"ANN401",
|
|
122
|
+
"D101",
|
|
123
|
+
"D107",
|
|
124
|
+
"ANN101",
|
|
125
|
+
"D105",
|
|
126
|
+
"D102",
|
|
127
|
+
"PD901",
|
|
128
|
+
"FBT001",
|
|
129
|
+
"EM101",
|
|
130
|
+
"TRY003",
|
|
131
|
+
"T201",
|
|
132
|
+
"B023",
|
|
133
|
+
"PERF203",
|
|
134
|
+
"FBT002",
|
|
135
|
+
"BLE001",
|
|
136
|
+
"COM812",
|
|
137
|
+
]
|
|
138
|
+
|
|
139
|
+
# Allow fix for all enabled rules (when `--fix`) is provided.
|
|
140
|
+
fixable = [
|
|
141
|
+
"ALL",
|
|
142
|
+
]
|
|
143
|
+
unfixable = [
|
|
144
|
+
]
|
|
145
|
+
|
|
146
|
+
# Allow unused variables when underscore-prefixed.
|
|
147
|
+
dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$"
|
|
148
|
+
|
|
149
|
+
[tool.ruff.format]
|
|
150
|
+
# Like Black, use double quotes for strings.
|
|
151
|
+
quote-style = "double"
|
|
152
|
+
|
|
153
|
+
# Like Black, indent with spaces, rather than tabs.
|
|
154
|
+
indent-style = "space"
|
|
155
|
+
|
|
156
|
+
# Like Black, respect magic trailing commas.
|
|
157
|
+
skip-magic-trailing-comma = false
|
|
158
|
+
|
|
159
|
+
# Like Black, automatically detect the appropriate line ending.
|
|
160
|
+
line-ending = "auto"
|
|
161
|
+
|
|
162
|
+
[tool.ruff.lint.pydocstyle]
|
|
163
|
+
convention = "google"
|
|
164
|
+
|
|
165
|
+
[tool.mypy]
|
|
166
|
+
python_version = "3.8"
|
|
167
|
+
ignore_missing_imports = true
|
|
168
|
+
follow_imports = "silent"
|
|
169
|
+
warn_redundant_casts = true
|
|
170
|
+
warn_unused_ignores = true
|
|
171
|
+
disallow_any_generics = true
|
|
172
|
+
check_untyped_defs = true
|
|
173
|
+
no_implicit_reexport = true
|
|
174
|
+
|
|
175
|
+
# for strict mypy: (this is the tricky one :-))
|
|
176
|
+
disallow_untyped_defs = true
|
albucore-0.0.1/setup.cfg
ADDED
albucore-0.0.1/setup.py
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import re
|
|
2
|
+
from pathlib import Path
|
|
3
|
+
from typing import List, Tuple
|
|
4
|
+
|
|
5
|
+
from pkg_resources import DistributionNotFound, get_distribution
|
|
6
|
+
from setuptools import find_packages, setup
|
|
7
|
+
|
|
8
|
+
INSTALL_REQUIRES = [
|
|
9
|
+
"numpy>=1.24.4",
|
|
10
|
+
"tomli>=2.0.1",
|
|
11
|
+
]
|
|
12
|
+
|
|
13
|
+
CHOOSE_INSTALL_REQUIRES = [
|
|
14
|
+
(
|
|
15
|
+
("opencv-python>=4.9.0", "opencv-contrib-python>=4.9.0", "opencv-contrib-python-headless>=4.9.0"),
|
|
16
|
+
"opencv-python-headless>=4.9.0",
|
|
17
|
+
),
|
|
18
|
+
]
|
|
19
|
+
|
|
20
|
+
def get_version() -> str:
|
|
21
|
+
current_dir = Path(__file__).parent
|
|
22
|
+
version_file = current_dir / "albucore" / "__init__.py"
|
|
23
|
+
with open(version_file, encoding="utf-8") as f:
|
|
24
|
+
version_match = re.search(r'^__version__ = [\'"]([^\'"]*)[\'"]', f.read(), re.M)
|
|
25
|
+
if version_match:
|
|
26
|
+
return version_match.group(1)
|
|
27
|
+
raise RuntimeError("Unable to find version string.")
|
|
28
|
+
|
|
29
|
+
def get_long_description() -> str:
|
|
30
|
+
base_dir = Path(__file__).parent
|
|
31
|
+
with open(base_dir / "README.md", encoding="utf-8") as f:
|
|
32
|
+
return f.read()
|
|
33
|
+
|
|
34
|
+
def choose_requirement(mains: Tuple[str, ...], secondary: str) -> str:
|
|
35
|
+
for main in mains:
|
|
36
|
+
try:
|
|
37
|
+
# Extract the package name from the requirement string
|
|
38
|
+
package_name = re.split(r"[!<>=]", main)[0]
|
|
39
|
+
# Check if the package is already installed
|
|
40
|
+
get_distribution(package_name)
|
|
41
|
+
return main
|
|
42
|
+
except DistributionNotFound:
|
|
43
|
+
continue
|
|
44
|
+
return secondary
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def get_install_requirements(install_requires: List[str], choose_install_requires: List[Tuple[Tuple[str, ...], str]]) -> List[str]:
|
|
48
|
+
for mains, secondary in choose_install_requires:
|
|
49
|
+
install_requires.append(choose_requirement(mains, secondary))
|
|
50
|
+
return install_requires
|
|
51
|
+
|
|
52
|
+
setup(
|
|
53
|
+
name="albucore",
|
|
54
|
+
version=get_version(),
|
|
55
|
+
description='A high-performance image processing library designed to optimize and extend the Albumentations library with specialized functions for advanced image transformations. Perfect for developers working in computer vision who require efficient and scalable image augmentation.',
|
|
56
|
+
long_description=get_long_description(),
|
|
57
|
+
long_description_content_type="text/markdown",
|
|
58
|
+
author="Vladimir I. Iglovikov",
|
|
59
|
+
license="MIT",
|
|
60
|
+
url="https://github.com/albumentations-team/albucore",
|
|
61
|
+
packages=find_packages(exclude=["tests", "benchmark", ".github"]),
|
|
62
|
+
python_requires=">=3.8",
|
|
63
|
+
install_requires=get_install_requirements(INSTALL_REQUIRES, CHOOSE_INSTALL_REQUIRES),
|
|
64
|
+
classifiers=[
|
|
65
|
+
"Development Status :: 4 - Beta",
|
|
66
|
+
"Intended Audience :: Developers",
|
|
67
|
+
"Intended Audience :: Science/Research",
|
|
68
|
+
"License :: OSI Approved :: MIT License",
|
|
69
|
+
"Operating System :: OS Independent",
|
|
70
|
+
"Programming Language :: Python",
|
|
71
|
+
"Programming Language :: Python :: 3",
|
|
72
|
+
"Programming Language :: Python :: 3.8",
|
|
73
|
+
"Programming Language :: Python :: 3.9",
|
|
74
|
+
"Programming Language :: Python :: 3.10",
|
|
75
|
+
"Programming Language :: Python :: 3.11",
|
|
76
|
+
"Programming Language :: Python :: 3.12",
|
|
77
|
+
"Topic :: Software Development :: Libraries",
|
|
78
|
+
"Topic :: Software Development :: Libraries :: Python Modules",
|
|
79
|
+
"Topic :: Scientific/Engineering :: Artificial Intelligence",
|
|
80
|
+
"Topic :: Scientific/Engineering :: Image Processing",
|
|
81
|
+
"Typing :: Typed"
|
|
82
|
+
],
|
|
83
|
+
keywords=[
|
|
84
|
+
"Image Processing", "Computer Vision", "Image Augmentation", "Albumentations", "Optimization", "Machine Learning",
|
|
85
|
+
"Deep Learning", "Python Imaging", "Data Augmentation", "Performance", "Efficiency", "High-Performance",
|
|
86
|
+
"CV", "OpenCV", "Automation"
|
|
87
|
+
],
|
|
88
|
+
zip_safe=False
|
|
89
|
+
)
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import numpy as np
|
|
2
|
+
import pytest
|
|
3
|
+
import cv2
|
|
4
|
+
from albucore.utils import MAX_VALUES_BY_DTYPE, clip
|
|
5
|
+
import albucore
|
|
6
|
+
|
|
7
|
+
# Pre-defined images for testing
|
|
8
|
+
UINT8_IMAGE = np.random.randint(0, 255, (3, 3, 3), dtype=np.uint8)
|
|
9
|
+
FLOAT32_IMAGE = np.random.random((3, 3, 3)).astype(np.float32)
|
|
10
|
+
|
|
11
|
+
# Test data combining both scalar and vector multipliers
|
|
12
|
+
test_data = [
|
|
13
|
+
(UINT8_IMAGE, 1.5),
|
|
14
|
+
(FLOAT32_IMAGE, 1.5),
|
|
15
|
+
(UINT8_IMAGE, np.array([1.5, 0.75, 1.1], dtype=np.float32)),
|
|
16
|
+
(FLOAT32_IMAGE, np.array([1.5, 0.75, 1.1], dtype=np.float32))
|
|
17
|
+
]
|
|
18
|
+
|
|
19
|
+
@pytest.mark.parametrize("image, multiplier", test_data)
|
|
20
|
+
def test_multiply(image, multiplier):
|
|
21
|
+
max_value = MAX_VALUES_BY_DTYPE[image.dtype]
|
|
22
|
+
|
|
23
|
+
result = albucore.multiply(image, multiplier)
|
|
24
|
+
|
|
25
|
+
numpy_result = image * multiplier
|
|
26
|
+
numpy_result = np.clip(0, max_value, numpy_result).astype(image.dtype)
|
|
27
|
+
|
|
28
|
+
# Check that all results match expected dtype and value arrays
|
|
29
|
+
assert result.dtype == image.dtype, "Result dtype does not match expected dtype."
|
|
30
|
+
assert np.array_equal(result, numpy_result), "Result does not match NumPy result."
|
|
31
|
+
|
|
32
|
+
@pytest.mark.parametrize("input_img, dtype, expected", [
|
|
33
|
+
(np.array([[-300, 0], [100, 400]], dtype=np.float32), np.uint8, np.array([[0, 0], [100, 255]], dtype=np.float32)),
|
|
34
|
+
(np.array([[-0.02, 0], [0.5, 2.2]], dtype=np.float32), np.float32, np.array([[0, 0], [0.5, 1.0]], dtype=np.float32))
|
|
35
|
+
])
|
|
36
|
+
def test_clip(input_img, dtype, expected):
|
|
37
|
+
clipped = clip(input_img, dtype=dtype)
|
|
38
|
+
assert np.array_equal(clipped, expected)
|