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 L_SetPaintIntensity, L_SetPaintContrast, and L_SetPaintGamma functions. These functions 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 functions can be more useful than the image processing functions 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 L_ChangeBitmapIntensity, L_ChangeBitmapContrast, and L_GammaCorrectBitmap or L_GammaCorrectBitmapExt. If you use these functions, the changes become permanent when you save the bitmap in a file.

The L_AddBitmaps function can be used to improve the brightness of an image by adding bitmaps within a bitmap list. The bitmaps in the list consist of several "versions" of the same view or image.

The L_AddWeightedBitmaps function can be used to improve the brightness of an image by adding bitmaps within a bitmap list. Typically, you would call this function for a series of images taken for the same object at short intervals. This function can also be used to obtain an image as the sum of several weighted images.

The L_MultiplyBitmap function 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 L_AdaptiveContrastBitmap function performs adaptive contrast enhancement (ACE) to areas that are originally low in contrast.

The L_ColorIntensityBalance function changes the distribution of the red, green, or blue channels.

The L_ContBrightIntBitmap function applies brightness, contrast and intensity adjustments to enhance the image tonal range.

The L_BrightnessDetection function can filter out the extra brightness in overexposed images captured by portable devices.

The L_ChangeHueSatIntBitmap function can be used to change the hue, saturation and brightness of all or specified colors in the image. This function combines the functionality found in the L_ChangeBitmapHue, L_ChangeBitmapSaturation, and L_ChangeBitmapIntensity functions 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 L_MathFunctionBitmap function 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.

When working with DICOM files, you can remap pixel values using a lookup table, or by applying a linear transformation using L_ApplyModalityLUT or L_ApplyLinearModalityLUT, respectively. You can also set up window leveling options for a bitmap using a lookup table or a linear transformation using L_ApplyVOILUT or L_ApplyLinearVOILUT, respectively.

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 L_HistoContrastBitmap function is similar to the ordinary L_ChangeBitmapContrast function, except that it uses a bitmap-specific middle value. The ordinary contrast function raises all intensity values above 128 and lowers all values below 128. The L_HistoContrastBitmap function 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 functions, you pass a parameter to indicate how much to increase the contrast.

The L_StretchBitmapIntensity function improves the contrast of a flat image, while preserving the original number of different intensity values. Other contrast functions, where you specify the increase, can lose values at the top and bottom of the scale. This function, 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 function has no effect.

The L_LocalHistoEqualizeBitmap function 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 L_HistoEqualizeBitmap function is often the most effective function for bringing out hidden details through contrast improvement. Like the L_StretchBitmapIntensity function, 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 L_LightControlBitmap lightens or darkens all or part of a bitmap by remapping the pixel values. This function remaps the pixel values of the bitmap across the full range of available pixel values, in order to achieve the new average values passed in puLowerAvr, puAverage and puUpperAvr.

The L_AutoColorLevelBitmap function darkens dark values and lightens light values, enhancing shadows and brightening the image automatically.

The L_ColorLevelBitmap function applies color leveling to an image. It changes the image's shadows, midtones and highlights.

To create your own histogram-based function, you can use the L_GetBitmapHistogram function to get a bitmap's histogram. You can then manipulate the histogram to create a lookup table and call the L_RemapBitmapIntensity function to change the bitmap's intensities through the lookup table. The L_GetFunctionalLookupTable and L_GetUserLookUpTable functions provide a means of programmatically updating lookup tables before calling L_RemapBitmapIntensity.

To get the histogram for a 12 or 16-bit grayscale image, call L_GetBitmapHistogram. Please note that support for 12 and 16-bit grayscale images is only available in the Document and Medical Imaging toolkits.

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 functions automatically change the values of all planes, but if you create your own function, the decision is up to you. With the L_GetBitmapHistogram and L_RemapBitmapIntensity functions, 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 L_ColorSeparateBitmap function to do an HSV separation. You can then manipulate the value plane and recombine the color planes with the L_ColorMergeBitmap function.

In HSV color space, a color is represented by a hue, a saturation (amount of white) and a value (amount of darkness). These can be remapped using the L_RemapBitmapHue function. To convert between the HSV and RGB color space, use the L_HSVtoRGB and the L_RGBtoHSV functions.

Special Functions

The L_DynamicBinaryBitmap function 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 L_MultiScaleEnhancementBitmap function wraps techniques of image enhancements, such as contrast enhancement, edge enhancement and latitude reduction, for Computed Radiography (CR).

The L_SubtractBackgroundBitmap is useful, especially with medical images and grayscale bitmaps, in correcting nonuniform brightness. This function 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 function includes the functionality similar to that of the L_MultiplyBitmap in order to include the capability for increasing the brightness of the final image.

The following functions make special use of the master channel:

Calculating Master Channel Values

In order to speed up widely used image processing filters in LEADTOOLS, the grayscale value (master channel) of a colored image is calculated using the following formulas:

#define CalcGrayValue(r, g, b) ((L_UCHAR)(((L_UCHAR) (((2 * (L_UINT) (r)) + (5 * (L_UINT) (g)) + (L_UINT) (b) + 4) / 8)))) 
#define CalcGrayValue16(r, g, b) ((L_UINT16) (((2 * (L_UINT32) (r)) + (5 * (L_UINT32) (g)) + (L_UINT32) (b) + 4) / 8)) 
#define CalcGrayValue32(r, g, b) ((L_UINT32) (((2 * (L_UINT32) (r)) + (5 * (L_UINT32) (g)) + (L_UINT32) (b) + 4) / 8)) 

Help Version 22.0.2023.7.11
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.

LEADTOOLS Raster Imaging C API Help

Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.