#include "l_bitmap.h"
L_LTIMGCOR_API L_INT L_ColorizeGrayBitmap (pDstBitmap, pSrcBitmap, pGrayColors, uCount, uFlags)
pBITMAPHANDLE pDstBitmap; |
pointer to the destination bitmap handle |
pBITMAPHANDLE pSrcBitmap; |
pointer to the source bitmap handle |
pLTGRAYCOLOR pGrayColors; |
pointer to an array of structures |
L_UINT uCount; |
number of elements in the pGrayColors array |
L_UINT32 uFlags; |
flags |
Colors an 8, 12 or 16-bit grayscale bitmap. The function changes the color bits/pixel of the bitmap from the specified formats into 24-bit RGB format.
Parameter |
Description |
pDstBitmap |
Pointer to the destination bitmap that will contain the result of the function. The user should free the bitmap before passing it to the function. |
pSrcBitmap |
Pointer to the bitmap handle referencing the 8, 12 or 16-bit grayscale bitmap. pSrcBitmap will not be affected. |
pGrayColors |
Pointer to an array of LTGRAYCOLOR structures. The user specifies number of entries of the array. You can automatically color the bitmap by passing NULL value in this variable (in this case uCount will be ignored). |
uCount |
Number of entries in pGrayColors array. It can be any number as long as it represents pGrayColors correctly. 1 means there is one entry, 2 means there is two entries. If you set it as 0 then the function will return an error code. |
uFlags |
Reserved for future use. Must be 0. |
SUCCESS |
The function was successful. |
< 1 |
An error occurred. Refer to Return Codes. |
The function can be used as a visualization aid. More precisely, this function can be used to show variations in a bitmaps intensity values.
This function colors the grayscale bitmap by converting specified ranges of grayscale intensities into corresponding RGB values. Use the pGrayColors variable to set the intensity ranges and the RGB values.
Using this function you can show details that were never seen in the original bitmap. In 12 and 16-bit grayscale bitmaps, only the 8 most significant bits are displayed, whereas the rest are discarded. So by coloring these discarded bits you can make them visible instead.
The pDstBitmap is assumed to be uninitialized. If pDstBitmap contains a bitmap, you should free it prior to calling this function. The function will allocate and store a 24-bit bitmap in pDstBitmap.
If you pass NULL in the pGrayColors variable then the function colors the bitmap automatically using an algorithm that generates unique output colors. The output bitmap will contain 256 colors if the input bitmap is 8-bit, 4096 colors if the input bitmap is 12-bit and 65535 colors if the input bitmap is 16-bit. The uCount variable will be ignored if pGrayColors is NULL.
You do not have to fill uStructSize for all the elements of the pGrayColors array. You only need to fill uStructSize for the first element in the pGrayColors array.
The sample below shows you how to color a 16-bit grayscale bitmap using pGrayColors.
In a 16-bit grayscale bitmap, the lowest pixel value is 0 and the highest pixel value is 65535.
The colors from the input images will be colored as follows:
Pixel intensities from 0 9999 will be colored as Red.
Pixel intensities from 10000 19999 will be colored as Green.
Pixel intensities from 20000 29999 will be colored as Blue.
Pixel intensities from 30000 39999 will be colored as Cyan.
Pixel intensities from 40000 49999 will be colored as Magenta.
Pixel intensities from 50000 65535 will be colored as Yellow. (Note: the uThreshold value is ignored for the last entry in the pGrayColors array.)
For more information on filling the pGrayColors array to obtain this result, refer to the example.
To update a status bar or detect a user interrupt during execution of this function, refer to L_SetStatusCallback.
This function supports 8, 12 and 16-bit grayscale bitmaps only. Support for 12 and 16-bit grayscale images are available in the Document and Medical Imaging toolkits. It also can process the whole image or a region of the image. If a bitmap has a region, the effect is applied only to the region.
This function does not support 32-bit grayscale images. It returns the error code ERROR_GRAY32_UNSUPPORTED if a 32-bit grayscale image is passed to this function.
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, Linux.
Functions: |
L_WindowLevel, L_WindowLevelBitmap, L_GrayScaleToDuotone, L_GrayScaleToMultitone, L_ShiftBitmapData, L_SelectBitmapData, LTGRAYCOLOR, L_AdjustBitmapTint, L_ColorHalfToneBitmap |
Topics: |
|
|
|
|
|
|
This example loads a 16-bit grayscale bitmap and then colors it.
#define MAKE_IMAGE_PATH(pFileName) TEXT("C:\\Users\\Public\\Documents\\LEADTOOLS Images\\")pFileName
// Now we have the resulting image in color
L_INT ColorizeGrayBitmapExample(L_VOID)
{
L_INT nRet;
BITMAPHANDLE GrayBitmap; /* Bitmap handle to hold the source grayscale image. */
BITMAPHANDLE ColorBitmap; /* Bitmap handle to hold the destination color bitmap. */
pLTGRAYCOLOR pGrayColors;
/* Load the bitmap, and convert to a gray scale type */
nRet = L_LoadBitmap (MAKE_IMAGE_PATH(TEXT ("IMAGE1.CMP")), &GrayBitmap, sizeof (BITMAPHANDLE), 0, ORDER_BGR, NULL, NULL);
if(nRet !=SUCCESS)
return nRet;
nRet = L_GrayScaleBitmap(&GrayBitmap, 8);
if(nRet !=SUCCESS)
return nRet;
pGrayColors = (pLTGRAYCOLOR) malloc (sizeof(LTGRAYCOLOR) * 6);
pGrayColors[0].uStructSize = sizeof(LTGRAYCOLOR);
pGrayColors[0].uThreshold = 9999;
pGrayColors[0].crColor.rgbRed = 255;
pGrayColors[0].crColor.rgbGreen = 0;
pGrayColors[0].crColor.rgbBlue = 0;
pGrayColors[1].uThreshold = 19999;
pGrayColors[1].crColor.rgbRed = 0;
pGrayColors[1].crColor.rgbGreen = 255;
pGrayColors[1].crColor.rgbBlue = 0;
pGrayColors[2].uThreshold = 29999;
pGrayColors[2].crColor.rgbRed = 0;
pGrayColors[2].crColor.rgbGreen = 0;
pGrayColors[2].crColor.rgbBlue = 255;
pGrayColors[3].uThreshold = 39999;
pGrayColors[3].crColor.rgbRed = 0;
pGrayColors[3].crColor.rgbGreen = 255;
pGrayColors[3].crColor.rgbBlue = 255;
pGrayColors[4].uThreshold = 49999;
pGrayColors[4].crColor.rgbRed = 255;
pGrayColors[4].crColor.rgbGreen = 0;
pGrayColors[4].crColor.rgbBlue = 255;
pGrayColors[5].uThreshold = 59999; // This value will be ignored
pGrayColors[5].crColor.rgbRed = 255;
pGrayColors[5].crColor.rgbGreen = 255;
pGrayColors[5].crColor.rgbBlue = 0;
// Call the function
nRet = L_ColorizeGrayBitmap (&ColorBitmap, &GrayBitmap, pGrayColors, 6, 0);
if(nRet !=SUCCESS)
return nRet;
if(pGrayColors)
free (pGrayColors);
nRet = L_SaveBitmap(MAKE_IMAGE_PATH(TEXT("Result.BMP")), &ColorBitmap, FILE_BMP, 24, 0, NULL);
if(nRet !=SUCCESS)
return nRet;
//free bitmap
if(ColorBitmap.Flags.Allocated)
L_FreeBitmap(&ColorBitmap);
if(GrayBitmap.Flags.Allocated)
L_FreeBitmap(&GrayBitmap);
return SUCCESS;
}
Raster .NET | C API | C++ Class Library | JavaScript HTML5
Document .NET | C API | C++ Class Library | JavaScript HTML5
Medical .NET | C API | C++ Class Library | JavaScript HTML5
Medical Web Viewer .NET