LBitmap::RemapIntensity

#include "ltwrappr.h"

virtual L_INT LBitmap::RemapIntensity(pLUT, uLUTLen, uFlags)

Uses a lookup table to change the class object's bitmap intensity values. You can apply the change to red, green, blue, or all color channels.

Parameters

L_INT * pLUT

Table of uLUTLen integers containing lookup values.

L_UINT uLUTLen

Length of the lookup table.  Possible values are:

If the REMAP_NORMAL flag is used in the uFlags parameter:

2^(HighBit - LowBit + 1)

If the REMAP_NORMAL flag is not used in the uFlags parameter:

Value Meaning
65536 16-bit / sample image
4096 12-bit / sample image
256 8-bit / sample image

L_UINT uFlags

Flags that indicate:

You can combine values of each group when appropriate by using a bitwise OR ( | ). The following are valid values:

Flags indicate the color plane to update:

Value Meaning
CHANNEL_MASTER [0] All channels *.
CHANNEL_RED [1] Red channel only.
CHANNEL_GREEN [2] Green channel only.
CHANNEL_BLUE [3] Blue channel only.

Flag indicates whether to change the high bit or not:

Value Meaning
REMAP_CHANGEHIGHBIT [0x0010] Change the high bit of the bitmap (pBitmap->HighBit) according to the used data in the pLUT.

Flag indicates whether pLUT contains normal data:

Value Meaning
REMAP_NORMAL [0x0100] The data in the pLUT is normal data, in this case the uLUTLen should be equal to 2^(HighBit - LowBit + 1).

Returns

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

Comments

The current intensity values correspond to the table indexes. The values of the entries are the new values to be applied.

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.

The bitmap intensity level range depends on the resolution of the image:

Be sure that pLUT contains the number of the bitmap intensity levels. For example if the bitmap is 16-bit (the maximum bitmap intensity level is (2^16)-1).

This function can be used to implement end user features such as Photoshop Curves.

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

This function supports signed data images.

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.

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)) 

Required DLLs and Libraries

Platforms

Win32, x64.

See Also

Functions

Topics

Example

L_INT LBitmap__RemapIntensityExample(LBitmap & Bitmap, L_TCHAR * pszFile) 
{ 
   L_INT nRet; 
   L_UINT LookupTable[256]; 
    
   nRet =Bitmap.Load(pszFile); 
   if(nRet !=SUCCESS) 
      return nRet; 
 
   LookupTable[0] = 255; 
   LookupTable[255] = 0; 
 
   nRet =Bitmap.GetFunctionalLookupTable((L_INT*)LookupTable, 256, 0, 255, 0,  
                                          FLT_LINEAR); 
   if(nRet !=SUCCESS) 
      return nRet; 
   nRet =Bitmap.RemapIntensity((L_INT*)LookupTable, 256, CHANNEL_MASTER); 
   if(nRet !=SUCCESS) 
      return nRet; 
 
   return SUCCESS; 
} 
 
L_INT LBitmap__RemapIntensity_Signed_Example(LBitmap & Bitmap) 
{ 
   L_INT          nRet; 
   L_INT *        pLookupTable = NULL;  /* Array to hold lookup table*/ 
   L_INT          nMaxValue, nMinValue; 
   L_INT          nLutLen; 
 
   nLutLen = 1 << (Bitmap.GetHandle()->HighBit - Bitmap.GetHandle()->LowBit + 1);//Get the real LUT length 
 
   if(!Bitmap.GetHandle()->Flags.Signed) 
      return FAILURE; //The image should be signed 
 
   nMinValue   =  -1 * nLutLen/2; //This is the lowest expected value. 
   nMaxValue   =  nLutLen/2 - 1;  //This is the highest expected value. 
 
 
   pLookupTable = (L_INT *) malloc(nLutLen * sizeof(L_INT)); 
   if(pLookupTable == NULL) 
      return ERROR_NO_MEMORY; 
 
   memset(pLookupTable, 0, nLutLen * sizeof(L_INT)); 
 
   /*Get Lookup table where the array calculated by the linear function for all the items of the array is from 0 - nLutLen*/ 
   if(nMinValue < 0) 
      pLookupTable[nMinValue + nLutLen]    = nLutLen/2 - 1; 
   else 
      pLookupTable[nMinValue]    = nLutLen/2 - 1; 
 
   if(nMaxValue < 0) 
      pLookupTable[nMaxValue + nLutLen]  = -1 * nLutLen/2;  
   else 
      pLookupTable[nMaxValue]  = -1 * nLutLen/2; 
 
   //Generate a negative LUT. 
   nRet = Bitmap.GetFunctionalLookupTable(pLookupTable, nLutLen, -1 * nLutLen/2, nLutLen/2 - 1, 1, FLT_LINEAR|FLT_SIGNED); 
   if(nRet !=SUCCESS) 
      return nRet; 
 
   //Invert the Image. 
   nRet = Bitmap.RemapIntensity(pLookupTable, (L_UINT)nLutLen, CHANNEL_MASTER|REMAP_NORMAL); 
   if(nRet !=SUCCESS) 
      return nRet; 
 
   return SUCCESS; 
} 
Help Version 21.0.2021.7.2
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2021 LEAD Technologies, Inc. All Rights Reserved.

LEADTOOLS Raster Imaging C++ Class Library Help
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2021 LEAD Technologies, Inc. All Rights Reserved.