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!
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.
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
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