21
votes

Lighting problems are common and difficult. How does one detect and reduce light reflection to save more information from an image? I have tried several methods with OpenCV and Python without luck.

(Image with reflection)

image with light reflection

(Image without reflection)

image without light reflection

I tried converting to HSV color space, and apply Histogram Equalization to the V channel, with Clahe equalization:

import cv2
import numpy as np

image = cv2.imread('glare.png')

hsv_image = cv2.cvtColor(image, cv2.COLOR_RGB2HSV)
h, s, v = cv2.split(hsv_image)

clahe = cv2.createCLAHE(clipLimit=2.0, tileGridSize=(8,8))
v = clahe.apply(v)

hsv_image = cv2.merge([h, s, v])
hsv_image = cv2.cvtColor(hsv_image, cv2.COLOR_HSV2RGB)

cv2.imwrite('clahe_h.png', hsv_image)

results:

image after clahe equalization

As well I tried thresholding to find bright pixels and than use Image Inpainting to replace them with neighbouring pixels.

import cv2
import numpy as np

image = cv2.imread('glare.png')

gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
blurred = cv2.GaussianBlur(gray, (3,3), 0)
thresh = cv2.threshold(blurred, 225, 255, cv2.THRESH_BINARY)[1]

dst_TELEA = cv2.inpaint(image,thresh,3,cv2.INPAINT_TELEA)
cv2.imwrite('after_INPAINT.png',dst_TELEA)

results: (after threshold) after threshold

after inpainting

1
does this help? They claim to use adaptive thresholding, look here for example on using itKrupip
You could probably do an edge detection. You will get significant edges on the glass. Then you can map the pixels inside the edge boundary with the pixels outside. However, this would probably work only for this message. Also, try running CLAHE on all three channelsRick M.
Thanks, I tried adaptive thresholding but it does not produce any good results. @Rick M. Thanks, I would like to know what is the most proper method to deal with light reflection problems not only this situation but thanks for answer I will try it and will post results.Streem
Try using a threshold of 230 to 240, I tried it and it seems to detected the edges where you have the reflection perfectly. After this you could call inPaint. Most of the reflection/shadow removal methods I know of are edge-based methods. You might want to do some research on that.Rick M.
In the first example you're converting the image with cv2.COLOR_RGB2HSV. cv2.imread() outputs a BGR not RGB image. Anyway, did you find a solution eventually?Johan

1 Answers

1
votes

There's no general method for effective glare removal.

HSV + CLAHE is a good and common start, but industry methods "cheat" by assuming some information about the subject (human face, fruit on a conveyor belt, retina through an ophthalmoscope), and sometimes information about the lighting (white ceiling light with very sharp edges, for the images in this question).