#include "l_bitmap.h"
L_LTIMGCOR_API L_INT L_SubtractBackgroundBitmap (pBitmap, uRollingBall, uShrinkSize, uBrightnessFactor, uFlags)
Removes the background from the image.
Pointer to the bitmap handle that references the bitmap on which to apply the effect.
The radius (in pixels) of the ball that will roll over the entire image to determine the background. Recommended value is 50.
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). |
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.
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:
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. |
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. |
Value | Meaning |
---|---|
SUCCESS | The function was successful. |
< 1 | An error occurred. Refer to Return Codes. |
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:
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].
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.
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
Win32, x64, Linux.
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 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