Glare removal With Inpainting[OpenCV Python]

Sivaram Rasathurai
5 min readApr 6, 2020

This article is originally posted here

Glare is a visual sensation caused by excessive and uncontrolled brightness. It can be disabling or simply uncomfortable. It is subjective, and sensitivity to glare can vary widely. Older people are usually more sensitive to glare due to the ageing characteristics of the eye.

Glare Image

First, We need to detect the place where the glare exists. We can easily identify them using global binarization since when a glare exists commonly, that pixel value is higher than 180. Using that, we can detect the glare. So we need to get the pixels which are greater than 180, so then we do the removing part.

The following function is designed to create a mask of an image where pixels are colored white if their values are greater than 180, and black if their values are 180 or lower. In this mask, the areas of actual glare in the image are represented in white, while all other areas are depicted in black.

def create_mask(image):
gray = cv2.cvtColor( image, cv2.COLOR_BGR2GRAY )
blurred = cv2.GaussianBlur( gray, (9,9), 0 )
_,thresh_img = cv2.threshold( blurred, 180, 255, cv2.THRESH_BINARY)
thresh_img = cv2.erode( thresh_img, None, iterations=2 )
thresh_img = cv2.dilate( thresh_img, None, iterations=4 )
# perform a connected component analysis on the…

--

--

No responses yet