Skip to content

Commit 7b52151

Browse files
committed
Add color augmentation module with proper doctests and type hints
1 parent 7b2282d commit 7b52151

File tree

1 file changed

+18
-10
lines changed

1 file changed

+18
-10
lines changed

computer_vision/color_augmentation.py

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
import numpy as np
2+
import cv2
3+
14
"""
25
Color Augmentation Module for Computer Vision
36
@@ -7,17 +10,15 @@
710
Reference: https://en.wikipedia.org/wiki/Data_augmentation
811
"""
912

10-
import numpy as np
11-
import cv2
12-
13-
1413
def brightness_adjustment(image: np.ndarray, factor: float = 1.0) -> np.ndarray:
1514
"""
1615
Adjust image brightness by modifying the V channel in HSV color space.
1716
1817
Args:
1918
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+
)
2122
2223
Returns:
2324
Brightness adjusted image in BGR format
@@ -79,7 +80,8 @@ def saturation_adjustment(image: np.ndarray, factor: float = 1.0) -> np.ndarray:
7980
8081
Args:
8182
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)
8385
8486
Returns:
8587
Saturation adjusted image in BGR format
@@ -225,7 +227,8 @@ def channel_shuffle(image: np.ndarray) -> np.ndarray:
225227
dtype('uint8')
226228
"""
227229
channels = list(cv2.split(image))
228-
np.random.shuffle(channels)
230+
rng = np.random.default_rng()
231+
rng.shuffle(channels)
229232
return cv2.merge(channels)
230233

231234

@@ -264,12 +267,17 @@ def temperature_tint(
264267
"""
265268
Adjust color temperature and tint of an image.
266269
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.
268272
269273
Args:
270274
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+
)
273281
274282
Returns:
275283
Adjusted image in BGR format

0 commit comments

Comments
 (0)