Changing Brightness and Contrast
Basic Brightness and Contrast methods
With the basic brightness and contrast methods 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 methods 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 AddWeightedBitmaps method can be used to improve the brightness of an image by adding bitmaps within a bitmap list. Typically, you would call this method for a series of images taken for the same object at short intervals. This method can also be used to obtain an image as the sum of several weighted images.
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.
The ChangeHueSatInt 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 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.
(Medical only) When working with DICOM files, you can remap pixel values using a lookup table, or by applying a linear transformation using the ApplyModalityLUT method or the ApplyLinearModalityLUT method, respectively. You can also set up window leveling options for a bitmap using a lookup table or a linear transformation using the ApplyVOILUT method or the ApplyLinearVOILUT method, respectively. To get the number of colors in a LUT between the starting color and the ending color use the CountLUTColors method. If the LUT stored inside a bitmap is linear, you can get the width of the window of interest and the center of that window using the GetLinearVOILUT method.
Histogram-Based Contrast methods
Some image processing methods 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 method 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 methods:
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 method, 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.
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 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.
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 specified new average values.
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.
Special Functions
The SubtractBackground method is useful, especially with medical images and grayscale bitmaps, in correcting non-uniform 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.
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).