Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Determine if an image needs contrasting automatically in OpenCV

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.

like image 334
AruniRC Avatar asked Jan 10 '11 12:01

AruniRC


People also ask

How do I adjust the contrast of an image in OpenCV?

To increase the contrast levels of the image, simply multiply a constant positive value to each and every image pixel. Similarly if one wishes to decrease the contrast level of the image, then multiply a constant positive value less than 1 for each and every image pixel.

How do you find the contrast of an image?

Contrast is defined as the difference between the highest and lowest intensity value of the image. So you can easily calculate it from the respective histogram. Example: If you have a plain white image, the lowest and highest value are both 255, thus the contrast is 255-255=0.

How do you find the contrast of an image in Python?

Just as we saw previously, you can calculate the contrast by calculating the range of the pixel intensities i.e. by subtracting the minimum pixel intensity value from the histogram to the maximum one. You can obtain the maximum pixel intensity of the image by using the np.


1 Answers

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

like image 181
Paul R Avatar answered Sep 28 '22 17:09

Paul R