Sunday, 24 February 2013

Gray Scale and Equalizing Histogram

The short version:

  • Here is the function:
    • cvtColor(source, gray, CV_BGR2GRAY);\\converts to gray-scale
    • equalizeHist( gray , result ); 
  • Use the above code and you get a gray-scaled image with an improved contrast range.

The long version:

    The reason behind converting our coloured image to a gray-scaled image is to reduce the size of the matrix the computer has to process in order to deliver the result. An analogy to indulge the reader...

Imagine you have to bottles filled with water or coke (I like coke). One is a gallon bottle and the other is the overpriced 250 ml coke bottle, both have the same bottleneck. Now if you drain them, (into a bucket and a glass respectively never waste coke) the time it takes for the big bottle is incredibly large compared to 250 ml bottle. Similarly when you have a bottleneck such as your processor, you would definitely prefer that it takes less time to process the data you give it and give you a result in as close to real-time as possible.

Now that you have a simpler image you need the aspects of the image to have reasonable variation so that it is easier for the computer to differentiate between two types of grays and therefore we do the contrast magic.

And the result for gray-scaling and contrast enhancement (Histogram Equalization)

Image 1: Grayscale
And,

Image 2: Equalized Histogram
Note that in the second Image 2 the light intensity has been increased and the difference between black and white has been improved.




No comments:

Post a Comment