How to correct uneven illumination in images using MATLAB?

Sulla picture Sulla · Feb 15, 2012 · Viewed 15.9k times · Source

I am performing feature detection in a video using MATLAB. The lighting condition varies in different parts of the video, leading to some parts getting ignored while transforming the RGB images to binary images.

The lighting condition in a particular portion of the video also changes over the course of the video.

Can you suggest best method in MATLAB to balance the lighting across the frame and the video?

Answer

jilles de wit picture jilles de wit · Feb 16, 2012

You have two options, depending on what features you want to detect and what you want to do with the video.

  1. Ignore the illumination of the images because (as you have concluded) this contains useless or even misleading information for your feature detection.
  2. Try to repair the illumination unevenness (which is what you ask for).

1) Is quite easy to do: Convert your image to a colourspace that separates out illumination in a separate channel such as: HSV (ignore the V channel) Lab (ignore L) YUV (ignore Y) and perform your feature detection on the two remaining channels. Of these HSV is the best (as noted by Yves Daoust in the comments) YUV and Lab leave some illumination information in the UV / ab channels. In my experience the last two also work depending on your situation, but HSV is best.

2) Is harder. I'd start by converting the image to HSV. Then you do the reparation on just the V channel:

  • Apply a gaussian blur to the V channel image with a very large value for sigma. This gives you a local average for the illumination. Compute the global average V value for this image (this is one number). Then Subtract the local average value from the actual V value for each pixel and add the global average. You have now done very crude illumination equalization. You can play around a bit with the value for sigma to find a value that works best.
  • If this fails, look into the options zenopy gives in his answer.

Whichever method you choose, I advise you to concentrate on what you want to do (i.e. detect features) and choose intermediate steps such as this one that suffice for your needs. So quickly try something, see how this helps your feature detection,