Created
December 18, 2018 09:03
-
-
Save benjamintanweihao/888cce016629a3d5f49041b7a06a389c to your computer and use it in GitHub Desktop.
clahe.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import cv2 | |
def equalize_histogram(path): | |
# Color | |
print('Processing (Color): {}'.format(path)) | |
img = cv2.imread(path) | |
lab = cv2.cvtColor(img, cv2.COLOR_BGR2LAB) | |
lab_planes = cv2.split(lab) | |
# apply CLAHE to lightness channel | |
clahe = cv2.createCLAHE(clipLimit=10.0, tileGridSize=(8, 8)) | |
lab_planes[0] = clahe.apply(lab_planes[0]) | |
lab = cv2.merge(lab_planes) | |
img = cv2.cvtColor(lab, cv2.COLOR_LAB2BGR) | |
# cv2.imshow('image', img) | |
# cv2.waitKey(0) | |
# cv2.destroyAllWindows() | |
# cv2.imwrite(path, img) | |
return path | |
# equalize_histogram('/Users/benjamintan/PycharmProjects/clahe/1538636920.819418.png') | |
# equalize_histogram('/Users/benjamintan/PycharmProjects/clahe/1538637082.119816.png') | |
# equalize_histogram('/Users/benjamintan/PycharmProjects/clahe/1538637098.719877.png') | |
equalize_histogram('/Users/benjamintan/PycharmProjects/clahe/1538637121.319763.png') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment