Remaps the bitmap pixels through a lookup-table (LUT).
#include "ltwrappr.h"
virtual L_INT LBitmap::ApplyModalityLUT(pLUT, pLUTDescriptor, uFlags)
Pointer to the LUT which contains the lookup table. The length of the LUT is in pLUTDescriptor->uNumberOfEntries
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]) |
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. |
Value | Meaning |
---|---|
SUCCESS | 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:
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.
LBitmap::ApplyModalityLUT only works on grayscale bitmaps. Calling this function for non-grayscale bitmaps will return an error (ERROR_INV_PARAMETER).
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, 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.
Win32, x64.
L_INT LBitmap__ApplyModalityLUTExample(LBitmap *plBitmap, L_BOOL bLinear)
{
L_INT nRet;
if(bLinear)
{
nRet =plBitmap->ApplyLinearModalityLUT(0.0, 0.5, 0);
if(nRet !=SUCCESS)
return nRet;
}
else
{
L_UINT16 * 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] = (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
free(pLUT);
}
return SUCCESS;
}
Help Collections
Raster .NET | C API | C++ Class Library | HTML5 JavaScript
Document .NET | C API | C++ Class Library | HTML5 JavaScript
Medical .NET | C API | C++ Class Library | HTML5 JavaScript
Medical Web Viewer .NET
Multimedia
Direct Show .NET | C API | Filters
Media Foundation .NET | C API | Transforms
Supported Platforms
.NET, Java, Android, and iOS/macOS Assemblies
Imaging, Medical, and Document
C API/C++ Class Libraries
Imaging, Medical, and Document
HTML5 JavaScript Libraries
Imaging, Medical, and Document