Point Processing (Introduction to Video and Image Processing) Part 2

Exponential Mapping

The exponential mapping uses a part of the exponential curve. It can be expressed as

tmp26dc-92_thumb_thumb

where k is a parameter that can be used to change of shape of the transformation curve and c is a scaling constant that ensures that the maximum output value is 255. It is calculated as

tmp26dc-93_thumb_thumb

where umax is the maximum pixel value in the input image. k is normally chosen as a number just above 1. This will enhance details in the bright areas while decreasing detail in the dark areas. An example is illustrated in Fig. 4.7.

Please note that both linear and non-linear gray-level mapping can also be applied to color images. This is simply done by performing gray-level mapping on each of the three color channels.


Examples of logarithmic and exponential gray-level mappings. Logarithmic mapping is useful for bringing out details in dark images and exponential mapping is useful for bringing out details in bright images

Fig. 4.7 Examples of logarithmic and exponential gray-level mappings. Logarithmic mapping is useful for bringing out details in dark images and exponential mapping is useful for bringing out details in bright images

The Image Histogram

So now we know how to correct images using gray-level mapping, but how can we tell if an image is too dark or too bright?

The obvious answer is that we can simply look at the image. But we would like a more objective way of answering this question. Moreover, we are also interested in a method enabling a computer to automatically assess whether an image is too dark, too bright or has too low a contrast, and automatically correct the image using gray-level mapping. To this end we introduce a simple but powerful tool namely the image histogram. Everybody processing images should always look at the histogram of an image before processing it—and so should you!

A histogram showing the age distribution of the guests at a party. The horizontal axis represents age and the vertical axis represents the number of guests

Fig. 4.8 A histogram showing the age distribution of the guests at a party. The horizontal axis represents age and the vertical axis represents the number of guests

A histogram is a graphical representation of the frequency of events. Say you are at a party together with 85 other guests. You could then ask the age of each person and plot the result in a histogram, as illustrated in Fig. 4.8. The horizontal axis represents the possible ages and the vertical axis represents the number of people having a certain age. Each column is denoted a bin and the height of a bin corresponds to the number of guests having this particular age. This plot is the histogram of the age distribution among the guests at the party. If you divide each bin with the total number of samples (number of guests) each bin now represents the fraction of guests having a certain age—multiply by 100% and you have the numbers in percentages. We can for example see that 11.6% of the guests are 25 years old. In the rest of this topic we will denote the vertical axis in a histogram by frequency, i.e., the number of samples.

We now do exactly the same for the pixel values of an image. That is, we go through the entire image pixel-by-pixel and count how many pixels have the value 0, how many have the value 1, and so on up to 255. This results in a histogram with 256 bins and this is the image histogram.

If the majority of the pixels in an image have low values we will see this as most high bins being to the left in the histogram and can thus conclude that the image is dark. If most high bins are to the right in the histogram, the image will be bright. If the bins are spread out equally, the image will have a good contrast and vice versa. See Fig. 4.9.

Note that when calculating an image histogram the actual position of the pixels is not used. This means i) that many images have the same histogram and ii) that an image cannot be reconstructed from the histogram. In Fig. 4.10 four images with the same histogram are shown.

We can of course also calculate the histogram of a color image. This is done separately for each color channel. An example is shown in Fig. 4.11.

Four images and their respective histograms

Fig. 4.9 Four images and their respective histograms

Four images with the exact same histogram

Fig. 4.10 Four images with the exact same histogram

Histogram Stretching

Armed with this new tool we now seek a method to automatically correct the image so that it is neither too bright nor too dark and does not have too low contrast. In terms of histograms, this means that the histogram should start at 0 and end at 255.

The histograms of a color image

Fig. 4.11 The histograms of a color image

The concept of histogram stretching

Fig. 4.12 The concept of histogram stretching

We obtain this by mapping the left-most non-zero bin in the histogram to 0 and the right-most non-zero bin to 255, see Fig. 4.12.

We can see that the histogram has been stretched so that the very dark and very bright values are now used. It should also be noted that the distance between the different bins is increased, hence the contrast is improved. This operation is denoted histogram stretching and the algorithm is exactly the same as Eq. 4.3 with a and b defined as in Eq. 4.4. / is the left-most non-zero bin in the histogram and /2 is the right-most non-zero bin in the histogram of the input image.

An example of histogram stretching

Fig. 4.13 An example of histogram stretching

Conceptually it might be easier to appreciate the equation if we rearrange Eq. 4.3:

tmp26dc-101_thumb[2]

First the histogram is shifted left so that f1 is located at 0. Then each value is multiplied by a factor a so that the maximum value f2 – fi becomes equal to 255. In Fig. 4.13 an example of histogram stretching is illustrated.

If just one pixel has the value 0 and another 255, histogram stretching will not work, since f2 – f1 = 255. A solution is modified histogram stretching where small bins in the histogram are removed by changing their values to those of larger bins. But if a significant number of pixels with very small and very high values exit, we still have f2 – f1 = 255, and hence the histogram (and image) remains the same, see Fig. 4.15. A more robust method to improve the histogram (and image) is therefore to apply histogram equalization.

Next post:

Previous post: