Note: This post is split into two parts, the first part provides an introduction to the basics of digital images and it informally states and motivates the task of histogram equalization, in the second part we precisely formulate histogram equalization and then discuss the mathematical details of the solution to histogram equalization .
Since the past few days I have been reading upon the details behind histogram equalization, and must say I found it pretty interesting. For the uninitiated, histogram equalization is an image processing technique that enhances the contrast of an image. It should be present as a standard feature in your favorite image editing program and I bet most of you would have used it at some point or the other to make those overly “dark” images look relatively “brighter” and vice-versa. So, if you are curious about how exactly this histogram equalization fixes your images, read on.
Before I go any further, here are some basics about images. A digital image is basically a collection of pixels, so if your digital camera is rated as say a Mega Pixel (MP) camera, then your images can contain a maximum of pixels. Of course these pixels are arranged nicely in a rectangular array (matrix), say for the MP case. We then say that our MP camera has a maximum resolution of .
For the sake of further discussion let us consider a gray color or a “black & white” image of Lena of a very modest resolution (by the way Lena was a playboy model in the 70’s, see here and her picture is very often used in image processing literature…for obvious reasons I guess 😉 ). Below, you can see the image of Lena and a schematic of the corresponding rectangular array of pixels. The numbers (rough values just for illustration, not actual values) in the rectangular array indicate the intensity values recorded at each of the corresponding pixel locations of the image. The range of these intensity values in an image, in general is , where represents a totally dark (black) pixel and represents a totally bright (white) pixel, the values in between represent the intermediate shades of gray. So, the lower numbers in the range represent the darker shades of gray and the higher numbers represent the brighter shades of gray.
A digital image corresponds to a rectangular array of pixels.
Now, if you observe carefully, the intensity values in the above rectangular array do not span the whole range but instead fall in a narrower range, which represents relatively darker shades of gray. This is explains why the Lena image above looks “dark”.
A standard way to visualize the distribution of shades of gray in an image is to plot the histogram of the intensity values. Simply put, the histogram is like a bar graph with a bar for each of the possible intensity values () and, the height of each bar is proportional to the number of pixels in the image with that particular intensity value. The histogram for the Lena image is shown below:
Original Lena image, notice the dark gray shades in the image.
Histogram of the original Lena image, all the peaks exist only in the range 0 to 100.
You can observe that all the “peaks” (non-zero heights) in the above histogram exist only for intensity values less than a , which is expected as the Lena image only contains shades of gray in the range . Now, let us enhance the contrast of the Lena image using histogram equalization. The resulting contrast enhanced Lena image and the corresponding histogram are shown below:
Contrast enhanced Lena Image, notice the relatively brighter gray shades and subsequently much improved contrast in the image.
Histogram of the contrast enhanced Lena image, notice how the peaks are distributed uniformly over the full range 0 to 255.
We can clearly observe that the contrast enhanced Lena image looks “brighter” and “nicer” with much better contrast than the original Lena image. Also, the histogram of the contrast enhanced Lena image contains peaks with similar heights, spread uniformly over the full intensity range . Based on this, one might postulate that images with a uniform histogram should exhibit good contrast and look “nicer”. This is in fact true and histogram equalization is motivated by this very observation. In histogram equalization, we attempt to transform the histogram of a given image such that it becomes “more” uniform. So, how do we determine this transformation given an image in general ? For this, we need to consider a mathematical formulation of the histogram equalization task.