virtual L_INT LBitmap::AutoColorLevel (pLvlClr, uBlackClip, uWhiteClip, uFlags)
Applies one of several types of automatic color leveling to an image.
Pointer to a LVLCLR structure that specifies the color leveling information used by the function. If AUTO_NOPROCESS is not set in uFlags, you can pass NULL if you are not interested in using these values. If AUTO_NOPROCESS is set in uFlags, then this parameter cannot be NULL.
An unsigned integer that represents the percentage of black pixels to clip from the bitmap, in hundredths of a percent. Valid values range from 0 to 10000 (which represents 100%). Best results are found using 0.3 to 0.9 %. The default is DEFAULT_BLACK_CLIP, which indicates to clip 0.5% of the black pixels.
An unsigned integer that represents the percentage of pixels to clip from the bitmap, in hundredths of a percent. Valid values range from 0 to 10000 (which represents 100%). The default is DEFAULT_WHITE_CLIP, which indicates to clip 0.5% of the white pixels.
A flag that indicates the type of leveling to perform. Possible values are:
|AUTO_LEVEL||[0x0001] Perform leveling on the individual R, G and B channels, treating each of the R, G and B channels as a separate entity. It introduces color cast on the image.|
|AUTO_CONTRAST||[0x0002] Perform leveling on the MASTER * channel (the grayscale values of the pixels). No color cast will be introduced.|
|AUTO_INTENSITY||[0x0003] Perform leveling on the RGB channel (the sum of the R, G, and B channels). No color cast will be introduced.|
|AUTO_NOPROCESS||[0x0004] Do not process the bitmap. Just update pLvlClr with the color leveling information used. The color leveling information used depends on which of the other flags was set with AUTO_NOPROCESS. Only one other flag may be set with AUTO_NOPROCESS.|
|SUCCESS||The function was successful.|
|< 1||An error occurred. Refer to Return Codes.|
This function is useful for pre-processing images to improve barcode recognition results.
This function makes dark values darker and light values lighter, automatically enhancing shadows and brightening the image. It also maximizes the tonal range of the image. It enhances the contrast and intensity using the image's histogram and a color distribution-based algorithm.
Before calling LBitmap::AutoColorLevel, initialize the size of the LVLCLR structure. The other fields in the structure will be updated with the nMinInput, nMaxInput, nMinOutput, nMaxOutput and uGamma values used by the function for the appropriate channel(s).
If you set the AUTO_NOPROCESS flag in uFlags, the pLvlClr parameter will be updated with the color leveling information used by the LBitmap::AutoColorLevel function. If you then pass the updated pLvlClr structure to the LBitmap::ColorLevel function, you will obtain the same result that you would have obtained if you had called the LBitmap::AutoColorLevel function with the leveling flag by itself.
If you set AUTO_NOPROCESS in uFlags and pass NULL to pLvlClr, the function will return an error code.
If you pass only AUTO_NOPROCESS to uFlags, the function will return an error code.
If the image is a grayscale image, then AUTO_LEVEL, AUTO_CONTRAST and AUTO_INTENSITY give identical results. Also the member variables master, red, green and blue of the structure pLvlClr will have the same values.
If the bitmap has a region, the effect will be applied only on the region.
This function supports 12 and 16-bit grayscale and 48 and 64-bit color images. Support for 12 and 16-bit grayscale and 48 and 64-bit color images is available only in the Document/Medical toolkits.
This function does not support 32-bit grayscale images. It returns the error code ERROR_GRAY32_UNSUPPORTED if a 32-bit grayscale image is passed to this function.
This function does not support signed data images. It returns the error code ERROR_SIGNED_DATA_NOT_SUPPORTED if a signed data image is passed to this function.
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))
This example applies auto image leveling.
L_INT LBitmap__AutoColorLevelExample(LAnimationWindow * LAniWnd)
LVLCLR lc; /* Structure to hold the level values, used for display only */
/* Apply "Auto Leveling" to the bitmap */
lc.uStructSize = sizeof(LVLCLR);
nRet =LAniWnd->AutoColorLevel (&lc, DEFAULT_BLACK_CLIP, DEFAULT_WHITE_CLIP, AUTO_LEVEL);
wsprintf (buffer, TEXT("Min and Max input values for the blue channel using auto level are %d and %d"), lc.blue.nMinInput, lc.blue.nMaxInput);
Medical Web Viewer .NET