L_DigitalSubtractBitmap

L_LTIMGCOR_API L_INT L_DigitalSubtractBitmap (pBitmap, pMaskBitmap, uFlags);

pBITMAPHANDLE pBitmap;

/* pointer to the destination, live, bitmap handle */

pBITMAPHANDLE pMaskBitmap;

/* pointer to the source mask bitmap handle */

L_UINT uFlags;

/* flags that specify how to process the bitmap */

Subtracts the live (destination) bitmap from the mask (source) bitmap to show the differences between the two bitmaps.

Parameter

Description

pBitmap

Pointer to the bitmap handle referencing the live bitmap. The live bitmap is the destination bitmap that will contain the result of the subtraction.

pMaskBitmap

Pointer to the bitmap handle referencing the mask bitmap. The mask bitmap is the source bitmap. pMaskBitmap will not be affected.

uFlags

Flags that control how the function works. Valid values are 0 (which means no enhancement), one or both of the following values:

 

Value

Meaning

 

DS_CONTRASTENH

[0x0001] Perform a contrast enhancement after applying the subtraction.

 

DS_OPTIMIZERANGE

[0x0002] Optimize and increase the tonal range of the bitmap after applying the subtraction.

Returns

SUCCESS

The function was successful.

< 1

An error occurred. Refer to Return Codes.

Comments

Performs a digital subtraction between two images. The resulting image may be enhanced using the uFlags options. Digital subtraction is mainly used to show the differences or the changes between two images. For the process to be meaningful both images should be related to each other. Digital Subtraction Angiography (DSA) is a practical example of digital subtraction.

Digital Subtraction Angiography (DSA) and Quality Control (QC) are both major fields that use image subtraction. An example of DSA is explained below.

DSA is a technology used for the visualization of blood vessels in the human body. A mask image is obtained using X-ray film of the body part of interest. Then vessels of that part are injected using a contrast medium. A sequence of images is taken after the injection. These are called live images. After applying subtraction between the mask and live images the resulting images are images that show the passage of the contrast medium in the vessels.

Both pBitmap and pMaskBitmap should have the same bits per pixel, number of channels and image dimensions; otherwise the function will return an error code.

If DS_CONTRASTENH flag is set then the contrast of the subtracted image will be enhanced.

If DS_OPTIMIZERANGE flag is set then the tonal range of the subtracted image will be optimized. That is, the image intensity will be distributed among the full image intensity range.

The result of the subtraction is placed in pBitmap.

To update a status bar or detect a user interrupt during execution of this function, refer to L_SetStatusCallback.

This function supports 12 and 16-bit grayscale and 48 and 64-bit color images. Support for 12 and 16-bit grayscale and 48 and 64-bit color images is 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.

The sign flag in the BITMAPHANDLE structure must be the same for all images listed. That is, all images must be either signed or unsigned.

Required DLLs and Libraries

LTIMGCOR

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 2000 / XP/Vista.

See Also

Functions:

L_ShiftBitmapData, L_SelectBitmapData, L_ColorizeGrayBitmap, L_MultiScaleEnhancementBitmap, L_CombineBitmap

Topics:

Raster Image Functions: Modifying Intensity Values

 

Processing an Image

Example

This example loads the mask and live bitmaps and performs digital subtraction.

 L_INT DigitalSubtractBitmapExample(L_VOID)
{
   L_INT nRet;
   BITMAPHANDLE MaskBmp; /* Bitmap handle to hold the mask image. */
   BITMAPHANDLE LiveBmp;  /* Bitmap handle to hold the live image and then the result */
   /* Load the bitmap, keeping the bits per pixel of the file */
   nRet = L_LoadBitmap (TEXT("%UserProfile%\\My Documents\\LEADTOOLS Images\\mask.CMP"), &MaskBmp, sizeof(BITMAPHANDLE), 0, ORDER_BGRORGRAY, NULL, NULL); 
   if(nRet !=SUCCESS)
      return nRet;
   nRet = L_LoadBitmap (TEXT("%UserProfile%\\My Documents\\LEADTOOLS Images\\live.CMP"), &LiveBmp, sizeof(BITMAPHANDLE), 0, ORDER_BGRORGRAY, NULL, NULL); 
   if(nRet !=SUCCESS)
      return nRet;
   nRet = L_DigitalSubtractBitmap (&LiveBmp, &MaskBmp, DS_CONTRASTENH); 
   if(nRet !=SUCCESS)
      return nRet;
   // Now we have the resulting image in LiveBmp

   //free Bitmap
   nRet = L_SaveBitmap(TEXT("%UserProfile%\\My Documents\\LEADTOOLS Images\\Result.BMP"), &LiveBmp, FILE_BMP, 24, 0, NULL);
   if(nRet !=SUCCESS)
      return nRet;
   //free bitmap 
   if(LiveBmp.Flags.Allocated)  
      L_FreeBitmap(&LiveBmp);
   if(MaskBmp.Flags.Allocated) 
      L_FreeBitmap(&MaskBmp);  
   return SUCCESS;
}