L_ApplyModalityLUT
#include "l_bitmap.h"
L_INT EXT_FUNCTION L_ApplyModalityLUT (pBitmap, pLUT, pLUTDescriptor, uFlags)
pBITMAPHANDLE pBitmap; |
/* pointer to the main bitmap handle */ |
/* 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 Toolkit only.
Parameter |
Description |
|
pBitmap |
Pointer to the bitmap handle referencing the bitmap that will be changed. |
|
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 |
Indicates 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. Possible values may be one or an Or-ed combination of the following: |
|
|
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] If set, the function will 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 L_RemapBitmapIntensity because it remaps the bitmap pixel values through a LUT. The function differs from L_RemapBitmapIntensity as follows:
L_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.
L_ApplyModalityLUT only works on grayscale bitmaps. Calling this function for non-grayscale bitmaps will return an error (ERROR_INV_PARAMETER).
L_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, L_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).
val is remapped according to the LUT (values smaller than nFirstStoredPixelValueMapped are mapped to 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 be between –32768 and +32767.
If the bitmap is unsigned, the indices are unsigned and 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 (e.g. 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
LTIMG 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
Windows 95 / 98 / Me, Windows 2000 / XP.
See Also
Example
L_INT TestModalityLUT(pBITMAPHANDLE pBitmap, L_BOOL bLinear)
{
L_INT nRet;
if(bLinear)
{
nRet = L_ApplyLinearModalityLUT (pBitmap, 0.0, 0.5, 0);
}
else
{
L_UINT16 L_FAR* pLUT;
L_INT i;
DICOMLUTDESCRIPTOR LUTDescriptor;
// allocate and initialize the LUT
pLUT = 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 = L_ApplyModalityLUT(pBitmap, pLUT, &LUTDescriptor, 0);
// free the LUT
free(pLUT);
}
return nRet;
}