Changing Brightness and Contrast

Basic Brightness and Contrast Functions

With the basic brightness and contrast functions you can change the intensity or contrast using a flat scale, or you can adjust the gamma correction. Gamma correction changes brightness using a logarithmic scale to account for visual perception. You can apply the basic brightness and contrast functions either to the display or to a bitmap.

To adjust the display, use the PaintGamma, PaintIntensity, PaintContrast properties. These properties affect the display of all bitmaps. They are not really part of the image processing group, because they do not affect the bitmap. Nevertheless, these properties can be useful when the need for brightness and contrast improvement is device-specific, rather than image-specific.

To change the brightness and contrast of a bitmap, use the following methods:

GammaCorrect method

Intensity method

Contrast method

Histogram-Based Contrast Functions

Some image processing functions use an internally generated histogram for more sophisticated contrast improvements. The histogram is a table that reflects how many times each intensity value occurs in the bitmap.

The following high-level methods are based on histograms:

HistoContrast method

StretchIntensity method

HistoEqualize method

The HistoContrast method is similar to the ordinary Contrast method, except that it uses a bitmap-specific middle value. The ordinary contrast method raises all intensity values above 128 and lowers all values below 128. The HistoContrast method first finds the median intensity value in the bitmap. It then uses that median value, instead of 128, as the middle value. With either of these methods, you pass a parameter to indicate how much to increase the contrast.

The StretchIntensity method improves the contrast of a flat image, while preserving the original number of different intensity values. Other contrast methods, where you specify the increase, can lose values at the top and bottom of the scale. This method, instead, sets the lowest intensity value to 0 and the highest to 255, then remaps the original values proportionally. If the original values already range from 0 to 255, this method has no effect.

The HistoEqualize method is often the most effective function for bringing out hidden details through contrast improvement. Like the StretchIntensity method, it remaps the intensity values to use the full range of 0 to 255. But instead of remapping the values proportionally, it uniformly redistributes the values to balance the number of pixels across the range of intensities. Thus, clusters of similar intensity values in the original image are spread out, enabling you to see differences that were too subtle in the original.

The following elements let you create your own histogram-based function:

GetHistogram method

HistogramTable property

RemapIntensity method

RemapTable property

You can use the GetHistogram method to get a bitmap's histogram. You can then create a lookup table (RemapTable) based on the entries in the HistogramTable and call the RemapIntensity method to change the bitmap's intensities through the lookup table.

The intensity values are gray-level values. When changing the intensity values of a color image, the LEADTOOLS functions are actually changing the value of each color plane. The high-level methods automatically change the values of all planes, but if you create your own function, the decision is up to you. With the GetHistogram and RemapIntensity methods, you can manipulate an individual color plane, or you can manipulate all color planes by specifying the master channel.

For 12 or 16-bit grayscale images, use the GetHistogramGray method to get the bitmap's histogram. The HistogramGrayTable property and the HistogramGrayTableSize property provide information about the histogram itself.

With color images, you can preserve more natural colors by first using the ColorSeparate method to do an HSV separation. You can then manipulate the value plane and recombine the color planes with the ColorMerge method.

In HSV color space, a color is represented by a hue, saturation (amount of white) and a value (amount of darkness). These can be remapped using the RemapHue method. This method uses several tables in the remapping process, depending on the bits per pixel of the image. For a 16-bit grayscale image or a 48-bit color image, the tables used are the HTableL, MaskTableL, STableL and the VTableL properties. For an image of any other bits per pixel the tables are the HTable property, the MaskTable property, the STable property and the VTable property. The RemapHueTablesSize property indicates the number of entries in the remapping tables. To convert between the HSV and RGB color space, use the following:

HSV_HfromRGB method

HSV_SfromRGB method

HSV_VfromRGB method

RGBfromHSV method