I have a two bmp files of the same scene and I would like determine if one is more bright than the other. Similarly I have a set of bmps with different contrasts and another set of bmps with different saturation. How do I compare these images for brightness,contrast and saturation ? These test images are saved by a tool provided by the sensor manufacturer. I am using gcc 4.5.
2 Answers
To compare the brightness of two images you need to compare the grey value of the pixels (yes, one by one). In the RGB colour space the brightness (grey value) is the mean of R,G and B, so you have brightness = (R+G+B) / 3
Comparing the contrast and especially the saturation will prove to be not that easy, for a start you could have a look at HSL and HSV but in general I'd suggest to get a good book on the image processing topic.

- 6,913
- 4
- 34
- 42
-
what about using any library like opencv etc for this ? – johnny alpaca Jun 28 '12 at 06:21
-
TBH I've never used any of them. I just had a quick look at OpenCV's API Refernce and from what I saw, it seems to me it's more focused on image *transformation* than on image *analysis*. I could also find this SO article [1](http://stackoverflow.com/questions/487053/any-good-image-processing-book) with some references. I think you may add **analysis** to your search query in order to find a good reading that explains how *brightness*, *contrast*, *saturation*, etc are defined in digital images. – Havelock Jun 28 '12 at 08:30
The answer of (R+G+B)/3 is really not even a good approximation of brightness (at least from what we know today)!
[BRIGHTNESS] What you really SHOULD do is convert to another color scale and compare the brightness using that channel of a color scale that incorporates brightness into it. Look here!!!
Formula to determine brightness of RGB color
there are a great coupld of answers here that talk about conversion or RGB into luminance, etc...
[CONTRAST] Contrast is a function of the spread of the pixel values throughout the full range of possible pixel values. One understands the contrast by putting together a histogram of all the pixels (where the x axis represents the a pixel value, and the y axis represents how many pixels are of that value), and analyzing the histogram to understand if there is good distribution throught the entire range, or not. Comparing contrast can be done many ways, but potentially a good starting point, would be to find the pixel-value center point (average of the histogram data) of each image, and potentially some histogram width parameter (where lets say the width is about the center point and is large enough to incorporate 90% of all pixels), and compare the center and width parameters of both images. This is ONLY a starting point.
[SATURATION] To compare saturation, one might convert the image to the HSL colour space. The S in HSL stands for Saturation. Comparing saturation within this colour space becomes exactly like comparing brightness as outlined above!!!

- 1
- 1

- 7,033
- 2
- 19
- 33