Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How Can I Remove Drastic Brightness Variations In A Video?

I have a stream of images that I'm getting from a video camera. I've found that sometimes an image from the stream will have a large spike in brightness (every pixel jumps or drops in value), and then return to its normal brightness level in the next image.

This is a huge problem for my algorithms. Is there anyway I can prevent this spike in brightness? I was thinking of something like a low pass filter on each pixel, but I was wondering if anyone has more experience with this issue.

I will be designing in MATLAB and implementing in OpenCV. If either platform has some nifty functions I'd love to hear about them.

Thanks for your time!

like image 860
trianta2 Avatar asked Dec 07 '22 05:12

trianta2


2 Answers

A fairly naive solution is to convert your images into YUV color space, perform histogram equalization on the Y channel, and then convert back to RGB. This method attempts to normalize the luminance of the image to the same distribution for every frame, compensating for variations in brightness.

The code to do this in OpenCV is:

cv::cvtColor(img, img, CV_BGR2YUV);
std::vector<cv::Mat> channels;
cv::split(img, channels);
cv::equalizeHist(channels[0], channels[0]);
cv::merge(channels, img);
cv::cvtColor(img, img, CV_YUV2BGR);

This produces an effect shown below. Note that the brightness of the two images in the Equalized column is more similar than that of the two original images. Your mileage will vary.

Luminance Equalization

like image 89
Aurelius Avatar answered Feb 17 '23 04:02

Aurelius


Every pixel? Sounds like a lighting or camera problem. If you can't control for either, I'd just detect the bad frames and drop/ignore them. They are likely trouble anyway, since you may have areas that are saturated or clipped.

For detection I'd just start by looking at the low percentiles of the histogram in separate regions in the image, and looks for frames where they all jump up or down

like image 30
Francesco Callari Avatar answered Feb 17 '23 04:02

Francesco Callari