L_LightControlBitmap

#include "l_bitmap.h"

L_LTIMGCLR_API L_INT L_LightControlBitmap(pBitmap, puLowerAvr, puAvrage, puUpperAvr, uFlags)

Lightens or darkens all or part of a bitmap by remapping the pixel values. This function is also useful for pre-processing images for the purpose of improving barcode recognition results.

Parameters

pBITMAPHANDLE pBitmap

Pointer to the bitmap handle referencing the bitmap to be changed.

L_UINT * puLowerAvr

Pointer to an array containing the new average pixel value for those pixels with values between 0 and the average pixel value for the entire bitmap. The size of the array equals one, if uFlags is YUV_SPACE or GRAY_SPACE, or three, if uFlags is RGB_SPACE. If uFlags is RGB_SPACE the first element corresponds to the new blue lower average value, the second element to the green, and the last element to the red.

L_UINT * puAvrage

Pointer to an array containing the new average pixel value for the entire bitmap. The size of the array equals one, if uFlags is YUV_SPACE or GRAY_SPACE, or three, if uFlags is RGB_SPACE. If uFlags is RGB_SPACE the first element corresponds to the new blue average value, the second element to the green, and the last element to the red.

L_UINT * puUpperAvr

Pointer to an array containing the new average pixel value for those pixels with values between the average pixel value for the entire bitmap and the highest pixel value in the bitmap. The size of the array equals either one if uFlags is YUV_SPACE or GRAY_SPACE or three if uFlags is RGB_SPACE where the first element corresponds to the new blue upper side average value, the second element to the green, and the last element to the red.

L_UINT uFlags

Flag that indicates which color space to remap. Possible values are:

Value Meaning
RGB_SPACE [0x0001] Use the histogram of RGB color space. (separated channels)
YUV_SPACE [0x0002] Use the histogram of YUV color space.(Best results)
GRAY_SPACE [0x0004] Use the histogram of a gray level representation of the image.

Returns

Value Meaning
SUCCESS The function was successful.
< 1 An error occurred. Refer to Return Codes.

Comments

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.

This function remaps the pixel values of the bitmap across the full range of available pixel values, in order to achieve the values passed in puLowerAvr, puAvrage and puUpperAvr.

For example, call this function for a grayscale bitmap, with puAvrage containing 150, puLowerAvr containing 100 and puUpperAvr containing 190. The pixels of the bitmap will be remapped so that the new average pixel value for the entire bitmap will be 150, the new average value for those pixels with a value between 0 and the average value for the entire bitmap will be 100, and the new average value for those pixels with a value between the average value for the entire bitmap and the maximum pixel value in the bitmap will be 190.

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 in the Document and Medical Imaging toolkits.

To update a status bar or detect a user interrupt during execution of this function, refer to L_SetStatusCallback.

For an example, click here

To obtain this effect, the following settings were used with the function:

puLowerAvr = 100
puAvrage = 255
puUpperAvr = 255
uFlags = YUV_SPACE

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.

Required DLLs and Libraries

Platforms

Win32, x64, Linux.

See Also

Functions

Topics

Example

The following example loads a bitmap and applies light control function.

L_INT LightControlBitmapExample(L_VOID) 
{ 
   L_INT nRet; 
   BITMAPHANDLE LeadBitmap; /* Bitmap handle to hold the loaded image. */ 
   L_UINT  puLowerAvr[3]; 
   L_UINT puAverage[3]; 
   L_UINT puUpperAvr[3]; 
 
   puLowerAvr[0] = 100; /*for blue, gray or yuv*/ 
   puLowerAvr[1] = 120; /*for green*/ 
   puLowerAvr[2] = 80; /*for red*/ 
   puAverage[0] = 210; /*for blue, gray or yuy*/ 
   puAverage[1] = 210; /*for green*/ 
   puAverage[2] = 210; /*for red*/ 
   puUpperAvr[0] = 255; /*for blue, gray or yuv*/ 
   puUpperAvr[1] = 255; /*for green*/ 
   puUpperAvr[2] = 255; /*for red*/  
 
   /* Load the bitmap, keeping the bits per pixel of the file */ 
   nRet = L_LoadBitmap(MAKE_IMAGE_PATH(TEXT("dirty_barcode.jpg")), &LeadBitmap, sizeof(BITMAPHANDLE), 0, ORDER_BGR, NULL, NULL); 
   if(nRet !=SUCCESS) 
      return nRet; 
 
   /* change the lightness of the bitmap */ 
   nRet = L_LightControlBitmap(&LeadBitmap, puLowerAvr, puAverage, puUpperAvr, YUV_SPACE); 
   if(nRet !=SUCCESS) 
      return nRet; 
   nRet = L_SaveBitmap(MAKE_IMAGE_PATH(TEXT("Result.BMP")), &LeadBitmap, FILE_BMP, 24, 0, NULL); 
   if(nRet !=SUCCESS) 
      return nRet; 
   //free bitmap  
   if(LeadBitmap.Flags.Allocated)   
      L_FreeBitmap(&LeadBitmap);   
   return SUCCESS; 
} 

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

LEADTOOLS Raster Imaging C API Help