|
| 1 | +import numpy as np |
| 2 | +import cv2 |
| 3 | + |
1 | 4 | """ |
2 | 5 | Color Augmentation Module for Computer Vision |
3 | 6 |
|
|
7 | 10 | Reference: https://en.wikipedia.org/wiki/Data_augmentation |
8 | 11 | """ |
9 | 12 |
|
10 | | -import numpy as np |
11 | | -import cv2 |
12 | | - |
13 | | - |
14 | 13 | def brightness_adjustment(image: np.ndarray, factor: float = 1.0) -> np.ndarray: |
15 | 14 | """ |
16 | 15 | Adjust image brightness by modifying the V channel in HSV color space. |
17 | 16 |
|
18 | 17 | Args: |
19 | 18 | image: Input image in BGR format |
20 | | - factor: Brightness multiplication factor (0.0 = black, 1.0 = original, >1.0 = brighter) |
| 19 | + factor: Brightness multiplication factor ( |
| 20 | + 0.0 = black, 1.0 = original, >1.0 = brighter |
| 21 | + ) |
21 | 22 |
|
22 | 23 | Returns: |
23 | 24 | Brightness adjusted image in BGR format |
@@ -79,7 +80,8 @@ def saturation_adjustment(image: np.ndarray, factor: float = 1.0) -> np.ndarray: |
79 | 80 |
|
80 | 81 | Args: |
81 | 82 | image: Input image in BGR format |
82 | | - factor: Saturation factor (0.0 = grayscale, 1.0 = original, >1.0 = more saturated) |
| 83 | + factor: Saturation factor |
| 84 | + (0.0 = grayscale, 1.0 = original, >1.0 = more saturated) |
83 | 85 |
|
84 | 86 | Returns: |
85 | 87 | Saturation adjusted image in BGR format |
@@ -225,7 +227,8 @@ def channel_shuffle(image: np.ndarray) -> np.ndarray: |
225 | 227 | dtype('uint8') |
226 | 228 | """ |
227 | 229 | channels = list(cv2.split(image)) |
228 | | - np.random.shuffle(channels) |
| 230 | + rng = np.random.default_rng() |
| 231 | + rng.shuffle(channels) |
229 | 232 | return cv2.merge(channels) |
230 | 233 |
|
231 | 234 |
|
@@ -264,12 +267,17 @@ def temperature_tint( |
264 | 267 | """ |
265 | 268 | Adjust color temperature and tint of an image. |
266 | 269 |
|
267 | | - Temperature affects the blue-red balance, while tint affects the green-magenta balance. |
| 270 | + Temperature affects the blue-red balance, while tint affects the |
| 271 | + green-magenta balance. |
268 | 272 |
|
269 | 273 | Args: |
270 | 274 | image: Input image in BGR format |
271 | | - temperature: Temperature adjustment (-1.0 to 1.0, negative = cooler, positive = warmer) |
272 | | - tint: Tint adjustment (-1.0 to 1.0, negative = green, positive = magenta) |
| 275 | + temperature: Temperature adjustment ( |
| 276 | + -1.0 to 1.0, negative = cooler, positive = warmer |
| 277 | + ) |
| 278 | + tint: Tint adjustment ( |
| 279 | + -1.0 to 1.0, negative = green, positive = magenta |
| 280 | + ) |
273 | 281 |
|
274 | 282 | Returns: |
275 | 283 | Adjusted image in BGR format |
|
0 commit comments