2.6.3.8 imgSubtractBg(Pro)

Menu Information

Image: Arithmetic Transform: Subtract Background

Brief Information

Subtract image background

Additional Information

This feature is for OriginPro only.

Command Line Usage

1. imgSubtractBg r:=80;

2. imgSubtractBg r:=50 s:=s2 i:=80;

3. imgSubtractBg s:=s8 bg:=bright oimg:=mat(2);

X-Function Execution Options

Please refer to the page for additional option switches when accessing the x-function from script

Variables

Display
Name
Variable
Name
I/O
and
Type
Default
Value
Description
Input Matrix img

Input

Image

<active>

Specifies the input image. The default input is the active image.

Rolling Ball r

Input

int

20

Specifies the radius (in pixels) of the ball that will roll over the entire image to determine the background.

Shrink Size s

Input

int

radius

Specifies how to shrink the input image internally. If the image is minimized, the computation speed will increase, but the accuracy will decrease. Note that the shrinking will not affect the input image.
Option list

  • radius:Depend on Radius
    Shrinks the input image depending on the radius of the rolling ball.
  • s0:No Shrink
    Does not shrink the input image.
  • s2:Shrink 1/2
    Resizes the input image to half width and height.
  • s4:Shrink 1/4
    Resizes the input image to quarter width and height.
  • s8:Shrink 1/8

Resizes the input image to eighth width and height

Brightness i

Input

int

100

Specifies a brightness factor for increasing or decreasing the brightness of the image. Valid values range from 0 to 400.

Background bg

Input

int

dark

Specifies whether or not the background is darker than the foreground.
Option list

  • dark:Darker than the Foreground
    The background is darker than the foreground.
  • bright:Brighter than the Foreground
    The background is brighter than the foreground.
Show show

Input

int

result

Specifies whether to show the subtraction result or the background in the output image.
Option list

  • result:Result
    The output image shows the result of the subtraction between the background and the original image.
  • bg:Background
    The output bitmap shows only the background.
Output Image oimg

Output

Image

<new>

Specifies the output image. By default, a new image will be created and used as output.

See the syntax here.

Description

When analyzing the contents of an image, the background typically does not contain anything of interest. In fact, in many cases the background can interfere with your analysis. One way to deal with this is to subtract it from the image. Subtracting the background from the image can help to segment out the objects of interest and facilitate further processing.

Often, we do not have a previously recorded background or an image of the background without any foreground objects. In this case, background subtract requires estimating the background with some algorithm and then subtracting it from the original image. Two tools provided by OriginPro are capable of performing this kind of background subtraction. They are Subtract Background and Subtract Interpolated Background. The major difference between them is the algorithm which is used to generate the background.

With ImgSubtractBg X-function, the Subtract Background tool in OriginPro, you can subtract a background that is generated by the "rolling ball" algorithm from an input image. This algorithm interprets the input image as a 3-D surface with the z axis to be the intensity of the image. Next, it rolls a 3-D ball beneath the surface. Finally, the background is constructed by these points of the 3-D ball which are tangent to the surface. Note that it only works well for simple background, where the background is significantly brighter or darker than the foreground.

The tool uses a copy of the input image to generate the background, which may be shrunk according to the Shrink Size option. In addition, you can control the radius of the rolling ball. Both the size of the copy image and the radius of the rolling ball can affect the computation speed and the quality of the subtraction. Furthermore, you can determine the brightness of the output image. It is also allowed to specify whether to show the subtraction result or the background in the output image.

BKSubMethod1Setting2.png

Examples

In this example, we use the imgSubtractBg function to subtract the background from the input image:

  1. When the input image is active, select Image: Arithmetic Transform: Subtract Background. This opens the dialog of the X-Function.
  2. In the X-Function dialog, change the settings as the screenshot below and click OK to close the dialog.
    ImgSubtractBg help English files image002.jpg
    A new image is created as a result. We can see that the background is subtracted from the input image and the output image is brighter than the input.
ImgSubtractBg help English files image004.jpg
ImgSubtractBg help English files image006.jpg
Input image
Output image


Note: OriginPro includes the ability to automatically recalculate the analysis result of the background subtractoperation any time you change the parameters or update your source data. In addition, the settings for the analysis routine can be saved to an analysis theme for later use with similar data.

Algorithm

The computation mainly uses L_SubtractBackgroundBitmap() function from LEADTOOLS Main API. Please refer to the LEADTOOLS Main API Help file, Version 14 and read the L_SubtractBackgroundBitmap topic.

References

LEADTOOLS Main API Help file, Version 14

Related X-Functions

imgReplaceBg, imgSubtractInterpBG, imgMathfun, imgPixlog