Opencv – Determine if an image needs contrasting automatically in OpenCV

image processingopencv

OpenCV has a handy cvEqualizeHist() function that works great on faded/low-contrast images.
However when an already high-contrast image is given, the result is a low-contrast one. I got the reason – the histogram being distributed evenly and stuff.

Question is – how do I get to know the difference between a low-contrast and a high-contrast image?

I'm operating on Grayscale images and setting their contrast properly so that thresholding them won't delete the text i'm supposed to extract (thats a different story).
Suggestions welcome – esp on how to find out if the majority of the pixels in the image are light gray (which means that the equalise hist is to be performed)
Please help!

EDIT: thanks everyone for many informative answers. But the standard deviation calculation was sufficient for my requirements and hence I'm taking that to be the answer to my query.

Best Answer

You can probably just use a simple statistical measure of the image to determine whether an image has sufficient contrast. The variance of the image would probably be a good starting point. If the variance is below a certain threshold (to be empirically determined) then you can consider it to be "low contrast".