L_SubtractBackgroundBitmap

#include "l_bitmap.h"

L_LTIMGCOR_API L_INT L_SubtractBackgroundBitmap (pBitmap, uRollingBall, uShrinkSize, uBrightnessFactor, uFlags)

pBITMAPHANDLE pBitmap;

pointer to bitmap handle

L_UINT uRollingBall;

ball size

L_UINT uShrinkSize;

shrink size ratio

L_UINT uBrightnessFactor;

brightness factor

L_UINT uFlags;

process flags

Removes the background from the image.

Parameter Description
pBitmap Pointer to the bitmap handle that references the bitmap on which to apply the effect.
uRollingBall The radius (in pixels) of the ball that will roll over the entire image to determine the background. Recommended value is 50.
uShrinkSize Shrink size ratio used to minimize the image internally in order to increase the speed with little loss of accuracy. Possible values are:
  Value Meaning
  SBK_DEPEND [0] The Shrink Size depends on the ball size.
  SBK_1_1 [1] No Resize (Highest accuracy).
  SBK_1_2 [2] Resize to half width and height.
  SBK_1_4 [3] Resize to quarter width and height.
  SBK_1_8 [4] Resize to eighth width and height (very fast).
uBrightnessFactor Brightness factor for increasing or decreasing the brightness of the image.
  Valid values range from 0 400. If you pass 100 the brightness remains unchanged. Lower values darken the image while higher values lighten the image.
uFlags Flags that indicate whether the background is darker than the foreground, and whether to show the objects without the background. You must select one from each group. Possible values are:

 

  The following flags represent whether the background is darker than the foreground:
  Value Meaning
  SBK_BG_DARK [0x00000000] The background in the current image is darker than the foreground.
  SBK_BG_BRIGHT [0x00000001] The background in the current image is brighter than the foreground.
  The following flags represent whether to show the objects without a background:
  Value Meaning
  SBK_RES_SHOW [0x00000000] The output bitmap shows the result of the subtraction between the background and the original image.
  SBK_BG_SHOW [0x00000010] The output bitmap shows only the background.

Returns

SUCCESS

The function was successful.

< 1

An error occurred. Refer to Return Codes.

Comments

This function does not support signed data images. It returns the error code ERROR_SIGNED_DATA_NOT_SUPPORTED if a signed data image is passed to this function.

This function is useful, especially with medical images and grayscale bitmaps in correcting non-uniform brightness.

The rolling ball algorithm works as follows:

1. Consider the bitmap to be a 3-D surface and the z-axis to be the intensity of the image [The component V from the HSV color space].

2. Roll a 3-D ball beneath the surface so all the points of the ball are under the surface with one or more points of the ball tangent to the surface.

3. The tangent points to the rolling ball are considered to be the background.

Subtract the background from the original image.

The Rolling Ball Radius should be at least as large as the radius of the largest object in the image that is not part of the background to ensure the separation of the background from any objects.

A small radius allows the detection of small objects, whereas a larger radius will detect both small and large objects.

When subtracting the background, sometimes the result is dim. In such a case you can enhance the brightness after subtracting the background by using the uBrightness factor, which functions similar to L_MultiplyBitmap. Passing 100 for uBrightness leaves the brightness unchanged.

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.

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

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

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

Win32, x64, Linux.

See Also

Functions:

L_AddShadowBitmap, L_ChangeHueSatIntBitmap, L_ColorReplaceBitmap, L_ColorThresholdBitmap, L_DirectionEdgeStatisticalBitmap, L_GetBitmapStatisticsInfo, L_GetFeretsDiameter, L_GetObjectInfo, L_MathFunctionBitmap, L_RevEffectBitmap, L_SegmentBitmap, L_UserFilterBitmap

Topics:

Changing Brightness and Contrast

 

Raster Image Functions: Changing Brightness and Contrast

 

Raster Image Functions: Modifying Intensity Values

Example

#define MAKE_IMAGE_PATH(pFileName) TEXT("C:\\Users\\Public\\Documents\\LEADTOOLS Images\\")pFileName 
L_INT SubtractBackgroundBitmapExample(L_VOID) 
{ 
   L_INT nRet; 
   BITMAPHANDLE LeadBitmap;   /* Bitmap handle for the image */ 
   /* Load a bitmap at its own bits per pixel  */ 
   nRet = L_LoadBitmap (MAKE_IMAGE_PATH(TEXT("ImageProcessingDemo\\Image4.Tif")), &LeadBitmap, sizeof(BITMAPHANDLE), 0, ORDER_BGR, NULL, NULL); 
   if(nRet !=SUCCESS) 
      return nRet; 
   /* Apply Subtract Background effect on the image*/ 
   nRet = L_SubtractBackgroundBitmap(&LeadBitmap, 50, SBK_DEPEND, 0, SBK_BG_DARK | SBK_RES_SHOW); 
   if(nRet !=SUCCESS) 
      return nRet; 
   nRet = L_SaveBitmap(MAKE_IMAGE_PATH(TEXT("Result.BMP")), &LeadBitmap, FILE_BMP, 24, 0, NULL); 
   if(nRet !=SUCCESS) 
      return nRet; 
   //free bitmap 
   if(LeadBitmap.Flags.Allocated) 
      L_FreeBitmap(&LeadBitmap); 
   return SUCCESS; 
} 

Help Version 19.0.2017.10.27
Products | Support | Contact Us | Copyright Notices
© 1991-2017 LEAD Technologies, Inc. All Rights Reserved.
LEADTOOLS Raster Imaging C API Help