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 without 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:
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)
Use a polarizing filter. A circular polarizing filter helps reduce or remove glare. Just attach it to the lens and turn it until you see the glare disappear. Keep in mind that you will need to adjust the camera settings to let in more light.
Brief Description. The reflection operator geometrically transforms an image such that image elements, i.e. pixel values, located at position in an original image are reflected about a user-specified image axis or image point into a new position. in a corresponding output image.
Several techniques like Ghosting Cues, Perceptual Reflection Removal, and ERRNet has been proven effective for removing reflection.
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).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With