#include "ltwrappr.h"

virtual L_INT LBitmap::ApplyModalityLUT(pLUT, pLUTDescriptor, uFlags)

L_UINT16 * pLUT;

pointer to the lookup table to be applied to the bitmap


pointer to the structure describing the LUT parameters

L_UINT uFlags;


Remaps the bitmap pixels through a lookup-table (LUT).

Parameter Description
pLUT Pointer to the LUT which contains the lookup table. The length of the LUT is in pLUTDescriptor->uNumberOfEntries
pLUTDescriptor Pointer to a structure describing the LUT. The following structure members are used:
  Value Meaning
  nFirstStoredPixelValueMapped The first index whose remapped value is stored in the LUT. All pixels that are less than this value will be remapped to pLUT[0].
  uNumberOfEntries The number of entries in pLUT. All the pixels that are greater than nFirstStoredPixelValueMapped + uNumberOfEntries will be set to the last entry in the LUT (pLUT[uNumberOfEntries 1])
uFlags Flags which determine the behavior of this function. Use one value or use a bitwise OR ( | ) to combine values.Possible values are:
  Value Meaning
  M_LUT_SIGNED [0x0001] If set, the LUT entries are signed 16-bit values. If not set, the LUT entries are unsigned 16-bit values.
  M_LUT_UPDATE_MIN_MAX [0x0002] Update pBitmap->MinVal with the new minimum intensity value in the bitmap and pBitmap->MaxVal with the new maximum intensity value.
  M_LUT_USE_FULL_RANGE [0x0004] Do not mask the values in the LUT.
  M_LUT_ALLOW_RANGE_EXPANSION [0x0008] Allow the function to increase pBitmap->HighBit (if needed) to be able to hold the data range after applying modality LUT.



The function was successful.

< 1

An error occurred. Refer to Return Codes.


This function remaps the bitmap pixels through a lookup-table (LUT). In the DICOM world, this is referred to as "applying a non-linear Modality LUT".

This function is similar to LBitmap::RemapIntensity because it remaps the bitmap pixel values through a LUT. The function differs from LBitmap::RemapIntensity as follows:

The values in the LUT will be masked such that only the useful bits in the bitmap are considered. The values are considered as if the bitmap pixel values are normalized, LowBit = 0.

For example, if the bitmap is:

 BitsPerPixel = 12

 LowBit = 4

 HighBit = 10

then there are 10-4+1=7 valid bits. This means that there are 128 values to remap. For every pixel, LBitmap::ApplyModalityLUT will do the following:


Take the pixel value, shift it to the right by 4 and mask out the high bits, producing a value (val = 0..127).


Remap values according to the LUT (values smaller than nFirstStoredPixelValueMapped are mapped to the first LUT entry, while values greater than nFirstStoredPixelValueMapped + uNumberOfEntries are mapped to the last LUT entry)


After remapping, val is shifted to the left by 4 and will replace bits 4 thru 10 from the original bitmap

If the bitmap is signed, the indices for the LUT are assumed to be signed and to be between 32768 and +32767.

If the bitmap is unsigned, the indices are unsigned. The indices are between 0..65535.

It is recommended to always set the M_LUT_UPDATE_MIN_MAX flag.

This function is helpful in applying what is referred to as a "Non-Linear Modality LUT" in the DICOM world. According to the DICOM standard, a "Modality LUT" defines the transformation of manufacturer-dependent pixel values into pixel values which are manufacturer-independent (for example, Hounsfield units for CT, Optical Density for film digitizers, etc.).

This function supports 12 and 16-bit grayscale images. Support for 12 and 16-bit grayscale images is available only in the Document/Medical toolkits.

This function supports signed data images.

Required DLLs and Libraries


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


Win32, x64.

See Also


LBitmap::AdjustTint, LBitmap::GammaCorrectExt, LBitmap::RemapIntensity, LBitmap::ApplyLinearModalityLUT, LBitmap::ApplyVOILUT, LBitmap::ApplyLinearVOILUT, Class Members


Raster Image Functions: Modifying Intensity Values


Processing an Image


Changing Brightness and Contrast


Raster Image Functions: Changing Brightness and Contrast


L_INT LBitmap__ApplyModalityLUTExample(LBitmap *plBitmap, L_BOOL bLinear)  
   L_INT    nRet;  
      nRet =plBitmap->ApplyLinearModalityLUT(0.0, 0.5, 0); 
      if(nRet !=SUCCESS) 
         return nRet; 
      L_UINT16 *      pLUT;  
      L_INT                i;  
      // allocate and initialize the LUT 
      pLUT = (L_UINT16 *)malloc(0x10000 * sizeof(L_UINT16));  
         return ERROR_NO_MEMORY;  
      // set a LUT which reduces the intensity of each pixel to half 
      for(i = 0; i <= 0xFFFF; i++) 
         pLUT[i] = (L_UINT16 )(i / 2);  
      // fill the LUTDescriptor structure 
      LUTDescriptor.uStructSize = sizeof(DICOMLUTDESCRIPTOR);    
      LUTDescriptor.nFirstStoredPixelValueMapped = 0;  
      LUTDescriptor.uEntryBits = 16;  
      LUTDescriptor.uNumberOfEntries = 0x10000;  
      // apply the LUT    
      nRet =plBitmap->ApplyModalityLUT(pLUT, &LUTDescriptor, 0); 
      if(nRet !=SUCCESS) 
         return nRet; 
      // free the LUT 
   return SUCCESS; 
Help Version 20.0.2019.3.12
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2019 LEAD Technologies, Inc. All Rights Reserved.

LEADTOOLS Raster Imaging C++ Class Library Help