# Removing Glare from Image

Disclaimer: I am in NO way engaged in signal processing. Just very curious...

Ny question is, very simply: is it possible to apply software processing to an image to remove or reduce headlight glare?

It would be a picture such as this:

If this IS possible, is there a software library available for this? I don't care which language, I just want the capabilities. Slash does anyone know if there is current research on this?

• Is that "glare" or "lens flare"? – endolith Oct 13 '11 at 18:51
• Good point. I should clarify: I'm interested in normalizing the light level across the image (though specifically the cars). So, reduce the spot brightness/washout of headlights and increase the visibility of the cars themselves. So...glare or lens flare, either way (I guess). – BenCole Oct 13 '11 at 18:55
• Well there are ways to actually remove things like that, with deconvolution, I think, instead of just reducing their brightness, but I'm not sure – endolith Oct 13 '11 at 20:16
• I'm imagining something like this: ftp.cfar.umd.edu/pub/aagrawal/Glare/AgrawalGlareLowRes.pdf except a bit more advanced in that it (1) reduces the glare using similar methods described in that paper; then (2) removes the actual light source from the picture; and (3) [fuzzy about this step] reduces glare again and enhances area around the light source. – BenCole Oct 13 '11 at 20:29
• Well that example requires modifying the optics of the camera before taking pictures, it seems – endolith Oct 13 '11 at 20:56

The problem you might have is that when bright lights are present, the camera will be using a fast shutter speed to keep the image from saturating too much. All the detail you are interested in is in the bottom few bits of the data.

So even if you remove the glare and then try and pull the rest of the image up in level, it's very noisy. For example, if you take your image and play with the levels to pull up the darker sections and just allow the glare to clip, this is the result:

If that's OK for onward processing (I don't know what you have in mind) then you could maybe remove the glare by looking at distributions of saturated pixels, and expand into the "glow" around them.

A better solution (if you have the option) can be to use a high-dynamic range camera which has an non-linear response in the pixels, and also often 10 or 12 bits per pixel of usable resolution, which means you can keep 7-8 bits for the darker sections.

• Fair enough. You've given me a good direction to go off in though, so thanks! – BenCole Oct 14 '11 at 13:21
• You don't need a high dynamic range camera. You just need to take multiple pictures at different exposure levels. Canon cameras can be configured to do this automatically with CHDK firmware. chdk.wikia.com/wiki/Samples:_HDR – endolith Oct 29 '11 at 21:30
• @endolith - Yes, you don't need an HDR camera... if your scene is changing slowly enough you can do it in software. But for the picture above I'd doubt it - I do automotive vision systems and 30Hz is barely enough, I'd hate to have to wait for several frames to get data! – Martin Thompson Oct 29 '11 at 22:20
• Could you do rolling CHDK image updates? Rather than waiting for several discrete frames, have ranges like: {frame1,2,3,4}, {frame2,3,4,5}, {frame3,4,5,6}, etc? Or would this be too slow? – BenCole Nov 8 '11 at 22:14
• @BenCole: yes, that's workable some of the time, but even one extra frame of latency would be too much in some applications. In fact, the scene change from one frame to the next would mean that "HDR by stacking several exposures" wouldn't work out too well – Martin Thompson Nov 9 '11 at 10:20