Add histogram equalization fcn (#2049)
This commit is contained in:
1 parent
d68afedb32
commit
08d3119e09
3 files changed
+13
-7
No files matched your search
+10
-4
@@ -631,10 +631,16 @@ def augment_hsv(img, hgain=0.5, sgain=0.5, vgain=0.5):
|
||||
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
|
||||
|
||||
# Histogram equalization
|
||||
# if random.random() < 0.2:
|
||||
# for i in range(3):
|
||||
# img[:, :, i] = cv2.equalizeHist(img[:, :, i])
|
||||
|
||||
def hist_equalize(img, clahe=True, bgr=False):
|
||||
# Equalize histogram on BGR image 'img' with img.shape(n,m,3) and range 0-255
|
||||
yuv = cv2.cvtColor(img, cv2.COLOR_BGR2YUV if bgr else cv2.COLOR_RGB2YUV)
|
||||
if clahe:
|
||||
c = cv2.createCLAHE(clipLimit=2.0, tileGridSize=(8, 8))
|
||||
yuv[:, :, 0] = c.apply(yuv[:, :, 0])
|
||||
else:
|
||||
yuv[:, :, 0] = cv2.equalizeHist(yuv[:, :, 0]) # equalize Y channel histogram
|
||||
return cv2.cvtColor(yuv, cv2.COLOR_YUV2BGR if bgr else cv2.COLOR_YUV2RGB) # convert YUV image to RGB
|
||||
|
||||
|
||||
def load_mosaic(self, index):
|
||||
|
||||
Reference in new issue
Block a user