Skip to content

Instantly share code, notes, and snippets.

@imneonizer
Created September 6, 2019 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save imneonizer/c29453d1ddd2154904dcf0721be169ae to your computer and use it in GitHub Desktop.
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
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