Created
September 6, 2019 13:57
-
-
Save imneonizer/c29453d1ddd2154904dcf0721be169ae to your computer and use it in GitHub Desktop.
Short simple image processing script to automatically adjust brightness and contrast of input image
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 | |
import sys | |
import imutils | |
#-----Reading the image----------------------------------------------------- | |
img = cv2.imread('1.jpg') | |
#img = imutils.resize(img, width=400) | |
#cv2.imshow("img",img) | |
#-----Converting image to LAB Color model----------------------------------- | |
lab= cv2.cvtColor(img, cv2.COLOR_BGR2LAB) | |
#cv2.imshow("lab",lab) | |
#-----Splitting the LAB image to different channels------------------------- | |
l, a, b = cv2.split(lab) | |
#cv2.imshow('l_channel', l) | |
#cv2.imshow('a_channel', a) | |
#cv2.imshow('b_channel', b) | |
#-----Applying CLAHE to L-channel------------------------------------------- | |
clahe = cv2.createCLAHE(clipLimit=3.0, tileGridSize=(8,8)) | |
cl = clahe.apply(l) | |
#cv2.imshow('CLAHE output', cl) | |
#-----Merge the CLAHE enhanced L-channel with the a and b channel----------- | |
limg = cv2.merge((cl,a,b)) | |
#cv2.imshow('limg', limg) | |
#-----Converting image from LAB Color model to RGB model-------------------- | |
final = cv2.cvtColor(limg, cv2.COLOR_LAB2BGR) | |
cv2.imwrite('output.jpg', final) | |
#cv2.imshow('final', final) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment