LBitmap::WindowLevelFillLUT (Document/Medical Imaging only)

#include "ltwrappr.h"

virtual L_INT LBitmap::WindowLevelFillLUT(* pLUT, ulLUTLen, crStart, crEnd, nLow, nHigh, uLowBit, uHighBit, nMinValue, nMaxValue, nFactor, uFlags)

RGBQUAD L_HUGE * pLUT;

/* lookup table */

L_UINT32 ulLLUTLen;

/* number of entries */

COLORREF crStart;

/* start color */

COLORREF crEnd;

/* end color */

L_INT nLow;

/*low value for leveling */

L_INT nHigh;

/*high value for leveling */

L_UINT uLowBit;

/* low bit */

L_UINT uHighBit;

/* high bit */

L_INT nMinValue;

/* bitmap’s minimum value */

L_INT nMaxValue;

/* bitmap’s maximum value */

L_INT nFactor;

/* factor */

L_UINT uFlags;

/* flags */

Fills the user-allocated LUT with the selected LUT type based on the specified values. This function is available in Document/Medical toolkits only.

Parameter

Description

pLUT

Pointer to the lookup table to be filled by this function. For every intensity value between 0 and 2 raised to the power of (nHighBit - nLowBit + 1)-1 there should be a corresponding entry in the lookup table that contains an RGB quad.

ulLUTLen

Value indicating the number of entries pointed to by pLUT.

crStart

Starting color value for the gradient.

crEnd

Ending color value for the gradient.

nLow

The low value for the range to be filled.

nHigh

The high value for the range to be filled.

uLowBit

Value indicating the low bit used for leveling. 0 <= nLowBit <= nHighBit <= (11 for 12-bit grayscale or 15 for 16-bit grayscale).

uHighBit

Value indicating the high bit used for leveling. 0 <= nLowBit <= nHighBit <= (11 for 12-bit grayscale or 15 for 16-bit grayscale).

nMinValue

The bitmap's minimum value. This value can be obtained by LBitmap::GetMinMaxVal.

nMaxValue

The bitmap's maximum value. This value can be obtained by LBitmap::GetMinMaxVal.

nFactor

Value that indicates the factor to be applied in the function operation specified in the uFlag parameter. This parameter is used only if uFlags is FILLLUT_EXPONENTIAL, FILLLUT_LOGARITHMIC or FILLLUT_SIGMOID. If FILLLUT_EXPONENTIAL or FILLLUT_SIGMOID flag is selected, its value can be any integer (+/-). If FILLLUT_LOGARITHMIC flag is selected its value should be >= 0. If nFactor = 0, the lookup table will be filled linearly.

uFlags

Flags that indicate how the range is used to fill the LUT and the type of LUT.

 

The following flags indicate how the range is used to fill the LUT and whether the LUT contains signed or unsigned data:

 

Value

Meaning

 

FILLLUT_INSIDE

[0x0001] Fill the LUT between nLow and nHigh. (inside the nLow...nHigh range)

 

FILLLUT_OUTSIDE

[0x0002] Fill the LUT below nLow and above nHigh. (outside the nLow...nHigh range)

 

The following flags indicate the LUT type:

 

Value

Meaning

 

FILLLUT_LINEAR

[0x0010] LUT is linear.

 

FILLLUT_EXPONENTIAL

[0x0020] LUT is exponential.

 

FILLLUT_LOGARITHMIC

[0x0030] LUT is logarithmic.

 

FILLLUT_SIGMOID

[0x0030] LUT is sigmoid.

 

The following flags indicate whether the LUT contains signed or unsigned data:

 

Value

Meaning

 

FILLLUT_UNSIGNED

[0x0000] The LUT data is unsigned.

 

FILLLUT_SIGNED

[0x0100] The LUT data is signed.

Returns

SUCCESS

The function was successful.

< 1

An error occurred. Refer to Return Codes.

Comments

Use this function to fill in the LUT used in LBitmap::WindowLevel according to the LUT type flag.

If you select FILLLUT_LINEAR, the LUT will be filled as follows:

bInside

nMinValue-nLow

nLow-nHigh

nHigh-nMaxValue

FILLLUT_INSIDE

solid black (0,0,0)

color gradient ranging from crStart to crEnd

solid white (255,255,255)

FILLLUT_OUTSIDE

solid color (crStart)

grayscale values from solid black (0,0,0) to solid white (255, 255, 255)

solid color (crEnd)

The nFactor parameter is used for logarithmic, exponential, and sigmoid functions only. If nFactor = 0 the function performs a linear interpolation between the two points nLow and nHigh, and stores the results in the lookup table, regardless of the value in uFlags.

If uFlag is FILLLUT_EXPONENTIAL the value of nFactor modifies the lookup table values (see figure below) according to the following equations:

Y = uStart + (uEnd – uStart) * (exp ((nFactor/10. * (x-uStart))/(uEnd-uStart)) - nFirstValue) / (nLastValue – nFirstValue)

where :

nFirstValue = exp(0).

nLastValue = exp(nFactor)

x = the intensity value of the selected point

uStart = the nLow parameter of this function

uEnd = the nHigh parameter of this function

image\WinLevel2.gif

If uFlag is FILLLUT_LOGARITHMIC the value of nFactor modifies the lookup table values (see figure below) according to the following equations:

Y = uStart + (uEnd – uStart) * (ln (1 + (nFactor/10. * (x-uStart))/(uEnd- uStart)) - nFirstValue)/ (nLastValue – nFirstValue)

where:

nFirstValue = 0.

nLastValue = ln(1 + nFactor)

x = the intensity value of the selected point

uStart = the nLow parameter of this function

uEnd = the nHigh parameter of this function

 

image\WinLevel1.gif

If uFlag is FILLLUT_SIGMOID the value of nFactor modifies the lookup table values (see figure below)according to the following equations:

 

Y = uStart + (uEnd – uStart) * (1./ (1 + exp(2*nFactor/10. * (x-Center))/(uEnd- uStart)) - nFirstValue)/ (nLastValue – nFirstValue)

where:

 

nFirstValue = 1./(1+exp(2.*nFactor/10.*(nStart - Center)/ (uEnd- uStart))).

nLastValue = 1./(1+exp(2.*nFactor/10.*(nEnd - Center)/ (uEnd- uStart))).

Center = (nEnd + nStart)/2.

x = the intensity value of the selected point

uStart = the nLow parameter of this function

uEnd = the nHigh parameter of this function

 

image\WinLevel3.gif

If uFlag is FILLLUT_LINEAR, nFactor is ignored. The function fills the lookup table linearly.

Note: This function only works for 12 or 16 bit grayscale images. Trying to use this function with other images will result in an error.

You must allocate the memory for the LUT before calling this function. You can calculate the required size with (sizeof(RGBQUAD) * (1<<(pBitmap->HighBit - pBitmap->LowBit + 1))), as seen in the example below.

For example, suppose you are working with a 12 bit grayscale image. There are 4096 intensity levels in a 12 bit image (2 raised to the 12th power). Normally, the interval between 0 and 4095 for unsigned data would be mapped to colors between (0, 0, 0) and (255, 255, 255). With this function, any value that falls between the low level and the high level will be mapped to colors between the start color and the end color. If you do not want to use mapping, set the start and end colors equal.

If you only want to map the values between 1972 and 3273 (in a 12-bit unsigned image), then set nLow to 1972, set nHigh to 3273, and set bInside to TRUE. To map the values less than 1972 and greater than 3273, select the FILLLUT_OUTSIDE option.

For information on saving bitmaps that have been window leveled, refer to Saving Window-Leveled Bitmaps.

Required DLLs and Libraries

LTDIS

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::WindowLevel, Class Members

Topics:

Raster Image Functions: Palettes

 

Raster Image Functions: Displaying and Printing

 

Using Color Values in LEADTOOLS

 

Grayscale Images

 

Saving Window-Leveled Bitmaps

 

Color Halftones and Halftone Images

 

Raster Image Functions: Working with Color Halftones, Halftones, and Grayscale Images

 

Raster Image Functions: Processing an Image

Example

void WindowLevelFillLUTExample() 
{
   RGBQUAD L_HUGE* pLUT;
   L_INT nRet;
   L_INT nMin, nMax;
   L_INT nLowBit, nHighBit;
   LONG fSigned = 0 ;
   LBitmap myBitmap;

   LSettings::UnlockSupport(L_SUPPORT_MEDICAL, L_KEY_MEDICAL);
   nRet = myBitmap.Load(TEXT("d:\\work\\images\\gray16.tif"),16);

   myBitmap.GetMinMaxBits(&nLowBit, &nHighBit);
   myBitmap.GetMinMaxVal(&nMin, &nMax);

   /* allocate the lookup table */
   pLUT = (RGBQUAD L_HUGE*)malloc(sizeof(RGBQUAD) * (1<<(nHighBit - nLowBit + 1)));

    //set the FILLLUT_SIGNED flag for signed images
    fSigned = FILLLUT_UNSIGNED;
    if(myBitmap.IsPixelsSigned())
       fSigned = FILLLUT_SIGNED;

   /* fill the LUT with a color gradient */
   myBitmap.WindowLevelFillLUT((RGBQUAD L_HUGE*)pLUT,
                               1<<(nHighBit - nLowBit + 1),
                               RGB(255,0,0),    /* RED              */
                               RGB(0,0,255),    /* BLUE             */
                               23000,           /* Starting value   */
                               45000,           /* Ending value     */
                               nLowBit,         /* Bitmap's LowBit  */
                               nHighBit,        /* Bitmap's HighBit */
                               nMin,            /* Bitmap's MinVal  */
                               nMax,            /* Bitmap's MaxVal  */
                               10,   /*nFactor*/
                               FILLLUT_INSIDE|
                               FILLLUT_LINEAR|
                               fSigned         /* Fill Inside range*/);

   /* window level the bitmap using the new LUT */
   myBitmap.WindowLevelBitmap(nLowBit,
                                nHighBit,
                                (RGBQUAD L_HUGE*)pLUT,
                                1<<(nHighBit - nLowBit + 1),
                                ORDER_BGR);

   /* free the table */
   free(pLUT);
   return;
}