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:
The HueSaturationIntensity method can be used to change the hue, saturation and brightness of all or specified colors in the image. This method combines the functionality found in the Hue, Saturation, and Intensity method methods and allows you to change the overall hue, saturation and intensity all at one time, or adjust the parameters separately, or make adjustments in successive passes.
The MathFunction method can be used to adjust the hue, saturation and brightness of an image by applying one of five mathematical functions to a bitmap’s pixel values: square, square root, log, sine, and cosine and then multiplying the results by specified factor.
The AdaptiveContrast method performs adaptive contrast enhancement (ACE) to areas that are originally low in contrast.
The ColorIntensityBalance method changes the distribution of the red, green, or blue channels.
The ContrastBrightIntensity method applies brightness, contrast and intensity adjustments to enhance the image tonal range.
The Multiply method can be used to increase or decrease the brightness in the bitmap, by multiplying the colors in the specified bitmap by a value equal to the uFactor value divided by 100. For example, if uFactor is 131 the colors in the specified bitmap will be multiplied by 1.31.
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:
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:
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.
The AutoColorLevel method darkens dark values and lightens light values, enhancing shadows and brightening the image automatically.
The ColorLevel method applies color leveling to an image. It changes the image's shadows, midtones and highlights.
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. These are the HTable property, the MaskTable property, the STable property and the VTable property. To get or set the length of these tables used in the remapping process, use the RemapHueTablesSize property. To convert between the HSV and RGB color space, use the following:
The LightControl method lightens or darkens all or part of a bitmap by remapping the pixel values. This method remaps the pixel values of the bitmap across the full range of available pixel values, in order to achieve the new average values in the LightLowerAvr, LightAvr and LightUpperAvr properties.
The LocalHistoEqualize method linearizes the number of pixels locally in a bitmap, based on the specified color space. This can be used to bring out the detail in dark areas of an image, and smooth the edges between blocks.
Special Functions
The SubtractBackground method is useful, especially with medical images and grayscale bitmaps, in correcting nonuniform brightness. This method uses a rolling ball algorithm to determine what points are background points. A small rolling ball radius identifies small objects and a larger radius identifies both large and small objects. Because frequently the resulting image is dim, this method includes the functionality similar to that of the Multiply method in order to include the capability for increasing the brightness of the final image.
Special Functions
The DynamicBinary method converts a bitmap into a black and white image without changing its bits per pixel by using a local threshold value for each pixel of the image.
The MultiScaleEnhancement method wraps techniques of image enhancements, such as contrast enhancement, edge enhancement and latitude reduction, for Computed Radiography (CR).