LBitmap::ApplyModalityLUT

#include "ltwrappr.h"

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

L_UINT16 L_FAR*pLUT;

/* pointer to the lookup table to be applied to the bitmap */

pDICOMLUTDESCRIPTOR pLUTDescriptor;

/* pointer to the structure describing the LUT parameters */

L_UINT uFlags;

/* flags */

Remaps the bitmap pixels through a lookup-table (LUT). This function is available in the Medical Toolkits only.

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.

Returns

SUCCESS

The function was successful.

< 1

An error occurred. Refer to Return Codes.

Comments

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:

image\sqrblit.gif LBitmap::ApplyModalityLUT allows you to specify an incomplete LUT. Values less than the first mapped index will be mapped to the first entry in the palette. Values higher than "first mapped index" + "LUT length" will be mapped to the last entry in the LUT.

image\sqrblit.gif LBitmap::ApplyModalityLUT only works on grayscale bitmaps. Calling this function for non-grayscale bitmaps will return an error (ERROR_INV_PARAMETER).

image\sqrblit.gif LBitmap::ApplyModalityLUT can create signed bitmaps. The output bitmap will be signed (if M_LUT_SIGNED is set), or unsigned (M_LUT_SIGNED is not set).

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, let’s say the bitmap is:

 BitsPerPixel = 12

 LowBit = 4

 HighBit = 10

In this case, 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:

1.

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

2.

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)

3.

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

LTKRN

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

See Also

Functions:

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

Topics:

Raster Image Functions: Modifying Intensity Values

 

Processing an Image

 

Changing Brightness and Contrast

 

Raster Image Functions: Changing Brightness and Contrast

Example

L_INT TestModalityLUT(LBitmap *plBitmap, L_BOOL bLinear) 
{
   L_INT    nRet; 
   if(bLinear) 
   {   
      nRet = plBitmap->ApplyLinearModalityLUT(0.0, 0.5, 0); 
   }
   else
   {
      L_UINT16 L_FAR*      pLUT; 
      L_INT                i; 
      DICOMLUTDESCRIPTOR   LUTDescriptor; 

      // allocate and initialize the LUT
      pLUT = (L_UINT16 *)malloc(0x10000 * sizeof(L_UINT16)); 
      if(!pLUT) 
         return ERROR_NO_MEMORY; 

      // set a LUT which reduces the intensity of each pixel to half
      for(i = 0; i <= 0xFFFF; i++)
         pLUT[i] = i / 2; 

      // fill the LUTDescriptor structure
      SET_SIZE(&LUTDescriptor); 
      LUTDescriptor.nFirstStoredPixelValueMapped = 0; 
      LUTDescriptor.uEntryBits = 16; 
      LUTDescriptor.uNumberOfEntries = 0x10000; 

      // apply the LUT   
      nRet = plBitmap->ApplyModalityLUT(pLUT, &LUTDescriptor, 0); 

      // free the LUT
      free(pLUT);   
   }
   return nRet; 
}