L_RemapBitmapIntensity

#include "l_bitmap.h"

L_LTIMGCLR_API L_INT L_RemapBitmapIntensity(pBitmap, pLUT, uLUTLen, uFlags)

pBITMAPHANDLE pBitmap;

pointer to the bitmap handle

L_INT* pLUT;

table of uLUTLen integers containing lookup values

L_UINT uLUTLen;

length of the lookup table

L_UINT uFlags;

color plane indicator

Uses a lookup table to change a bitmap's intensity values.

Parameter Description
pBitmap Pointer to the bitmap handle referencing the bitmap to be changed.
pLUT Table of uLUTLen integers containing lookup values.
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
uFlags Flags that indicate:
  • The color plane to update.

  • Whether to change the high bit or not.

  • Whether the pLUT contains normal or stretched data.

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</b>* [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:
  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:
  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

SUCCESS

The function was successful.

< 1

An error occurred. Refer to Return Codes.

Comments

You can apply the change to red, green, blue, or all color channels.

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

The bitmap intensity level range depends on the resolution of the image. For 64-bit, 48-bit, and 16-bit bitmaps, the intensity levels range from 0 to 2^16-1. For 12-bit bitmaps, the intensity levels range from 0 to 2^12-1. For other resolutions, the intensity levels range from 0 to 255.

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 L_SetStatusCallback.

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.

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

LTIMGCLR

For a listing of the exact DLLs and Libraries needed, based on the toolkit version, refer to Files To Be Included With Your Application.

Platforms

Win32, x64, Linux.

See Also

Functions:

L_GetUserLookUpTable, L_GetFunctionalLookUpTable, L_ChangeBitmapIntensity, L_GammaCorrectBitmap, L_ChangeBitmapContrast, L_HistoContrastBitmap, L_StretchBitmapIntensity, L_InvertBitmap, L_ChangeBitmapHue, L_ChangeBitmapSaturation, L_HistoEqualizeBitmap, L_FillBitmap, L_GetPixelColor, L_PutPixelColor, L_GetBitmapHistogram, L_WindowLevel, L_ChannelMix, L_DeinterlaceBitmap, L_DesaturateBitmap, L_EdgeDetectStatisticalBitmap, L_LightControlBitmap, L_SmoothEdgesBitmap, L_LocalHistoEqualizeBitmap, L_AddWeightedBitmaps, L_ColorMergeBitmap, L_ColorSeparateBitmap, L_ConvertColorSpace, L_MultiplyBitmap, L_AutoColorLevelBitmap, L_ColorLevelBitmap, L_CorrelationBitmap, L_GrayScaleToDuotone, L_GrayScaleToMultitone, L_HolesRemovalBitmapRgn, L_SelectiveColorBitmap, L_SkeletonBitmap, L_ChangeHueSatIntBitmap, L_ColorReplaceBitmap, L_ColorThresholdBitmap, L_MathFunctionBitmap, L_SegmentBitmap, L_AdaptiveContrastBitmap, L_ApplyMathLogicBitmap, L_ColorIntensityBalance, L_ColorizeGrayBitmap, L_ContBrightIntBitmap, L_DigitalSubtractBitmap, L_DynamicBinaryBitmap, L_EdgeDetectEffectBitmap, L_FunctionalLightBitmap, L_MultiScaleEnhancementBitmap, L_SelectBitmapData, L_ShiftBitmapData

Topics:

Raster Image Functions: Modifying Intensity Values

 

Changing Brightness and Contrast

 

Raster Image Functions: Changing Brightness and Contrast

Example

This example will invert loaded bitmap by using lookup table affected by linear function

L_INT RemapBitmapIntensityExample(L_VOID) 
{ 
   L_INT nRet; 
   L_UINT LookupTable[256];  /* Array to hold lookup table*/ 
   BITMAPHANDLE LeadBitmap; /*Bitmap handle to hold the loaded image */ 
 
   /* Load the bitmap, forced to 24 per pixel */ 
   nRet = L_LoadBitmap (MAKE_IMAGE_PATH(TEXT("sample5.cmp")), &LeadBitmap, sizeof(BITMAPHANDLE), 24, ORDER_BGR, NULL, NULL);  
   if(nRet !=SUCCESS) 
      return nRet; 
   /*Get Lookup table where the array calculated by the linear function for all the items of the array is from 0 - 255*/ 
   LookupTable[0] = 255; 
   LookupTable[255] = 0;  
   nRet = L_GetFunctionalLookupTable ((L_INT *)LookupTable, 256,0, 255, 0, FLT_LINEAR); 
   if(nRet !=SUCCESS) 
      return nRet; 
   nRet = L_RemapBitmapIntensity(&LeadBitmap, (L_INT *)LookupTable, 256, CHANNEL_MASTER); 
   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; 
} 
 
//This example will convert all images to signed image and it will invert its data. 
L_INT RemapBitmapIntensity_Signed_Example(pBITMAPHANDLE pBitmap) 
{ 
   L_INT          nRet; 
   L_INT *        pLookupTable = NULL;  /* Array to hold lookup table*/ 
   L_INT          nMaxValue, nMinValue; 
   L_INT          nLutLen; 
 
   nLutLen = 1 << (pBitmap->HighBit - pBitmap->LowBit + 1);//Get the real LUT length 
 
   if(!pBitmap->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 = L_GetFunctionalLookupTable (pLookupTable, nLutLen, -1 * nLutLen/2, nLutLen/2 - 1, 1, FLT_LINEAR|FLT_SIGNED); 
   if (nRet != SUCCESS) 
   { 
      free(pLookupTable); 
      return nRet; 
   } 
 
   //Invert the Image. 
   nRet = L_RemapBitmapIntensity(pBitmap, pLookupTable, nLutLen, CHANNEL_MASTER|REMAP_NORMAL); 
   if (nRet != SUCCESS) 
   { 
      free(pLookupTable); 
      return nRet; 
   } 
 
   free(pLookupTable); 
 
   return SUCCESS; 
} 

Help Version 20.0.2018.2.25
Products | Support | Contact Us | Copyright Notices
© 1991-2018 LEAD Technologies, Inc. All Rights Reserved.
LEADTOOLS Raster Imaging C API Help