Skip to content

Commit

Permalink
hustvl#201 color format in HSV augmentation
Browse files Browse the repository at this point in the history
RahulRewale committed Dec 4, 2023
1 parent d80d574 commit b520bd5
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/utils/augmentations.py
Original file line number Diff line number Diff line change
@@ -9,7 +9,7 @@
def augment_hsv(img, hgain=0.5, sgain=0.5, vgain=0.5):
"""change color hue, saturation, value"""
r = np.random.uniform(-1, 1, 3) * [hgain, sgain, vgain] + 1 # random gains
hue, sat, val = cv2.split(cv2.cvtColor(img, cv2.COLOR_BGR2HSV))
hue, sat, val = cv2.split(cv2.cvtColor(img, cv2.COLOR_RGB2HSV))
dtype = img.dtype # uint8

x = np.arange(0, 256, dtype=np.int16)
@@ -18,7 +18,7 @@ def augment_hsv(img, hgain=0.5, sgain=0.5, vgain=0.5):
lut_val = np.clip(x * r[2], 0, 255).astype(dtype)

img_hsv = cv2.merge((cv2.LUT(hue, lut_hue), cv2.LUT(sat, lut_sat), cv2.LUT(val, lut_val))).astype(dtype)
cv2.cvtColor(img_hsv, cv2.COLOR_HSV2BGR, dst=img) # no return needed
cv2.cvtColor(img_hsv, cv2.COLOR_HSV2RGB, dst=img) # no return needed

# Histogram equalization
# if random.random() < 0.2:
@@ -211,6 +211,7 @@ def letterbox(combination, new_shape=(640, 640), color=(114, 114, 114), auto=Tru
combination = (img, gray, line)
return combination, ratio, (dw, dh)


def letterbox_for_img(img, new_shape=(640, 640), color=(114, 114, 114), auto=True, scaleFill=False, scaleup=True):
# Resize image to a 32-pixel-multiple rectangle https://github.com/ultralytics/yolov3/issues/232
shape = img.shape[:2] # current shape [height, width]

0 comments on commit b520bd5

Please sign in to comment.