## Histogram Equalization
(Version 1.1)

[Place this text file and the accompanying JPG images in the VirtualDub plugins directory to make it available via the Help button on the filter configuration dialog box. The computer must have an HTML browser, such as Internet Explorer or Netscape, available in its search path.]

This filter applies a global color histogram equalization on a per-frame basis. It can be used to correct video that has a compressed range of pixel intensities. The filter redistributes the pixel intensities to equalize their distribution across the intensity range. It may be viewed as an "automatically adjusting contrast filter". This filter is useful only for correcting degraded or poorly captured source video. It should not be applied willy-nilly, as it leads to a modification of image content.

Following are before and after images and histograms for a typical input frame, using strength 132 and maximum intensity 200, no antibanding (see note below on the histograms):

It can be seen that the output histogram is strongly banded due to the mapping of a small range of intensity values to a larger range. If the banded pixels are distributed spatially (as they are in our example), this may not be noticeable or objectionable in the output video. However, if the banded pixels are arrayed spatially, as you might get in a brightness gradient, you may see overt banding, or posterization. To combat this, an antibanding capability is provided. Following are the after image and histogram for the above example with strong antibanding enabled. The banding is greatly reduced but at the expense of the addition of some random intensity noise.

The following configuration options are supported:

Strength: This option determines the amount of equalization to be applied. As the strength is reduced, the distribution of pixel intensities more-and-more approaches that of the input frame.

Maximum Intensity: With some source material, and especially color source material, there can be a washing out at high strengths. This option sets the maximum intensity that can generated and scales the output values appropriately. The strength should be set as desired and then the intensity can be limited if needed to avoid washing-out.

Enable weak antibanding: Randomly varies the luminance of output pixels by a small amount to avoid banding of the histogram.

Enable strong antibanding: Randomly varies the luminance of output pixels by a large amount to avoid banding of the histogram.

This filter displays the input and output histograms using its own code, and not VirtualDub's. By placing the VirtualDub internal levels filter after this filter, and then selecting Preview followed by Sample frame, VirtualDub's idea of the output histogram can be inspected. Unfortunately, the levels filter histogram display in versions of VirtualDub prior to 1.4.5 are bug-ridden. The histograms shown here were obtained from this filter's displays. The levels filter's histogram display operates correctly in VirtualDub version 1.4.5.

Finally, be aware that applying equalization to a color image can be problematic because the equalization is based on the image luminance. Consider an image that is predominantly bluish. The contribution of blue to luminance is low. Thus, even if we make all the blues full intensity, we will not see high luminance values. That is why in such a case the equalization does not spread the luminances into the histogram's upper end. Good spreading will occur when the image has a good balance of all the color channels.

For additional information, version updates, and other filters, please go to the following web site:

Filters for VirtualDub
http://sauron.mordor.net/dgraft/index.html

Donald Graft
July 8, 2001
(C) Copyright 2001, All Rights Reserved