OriginLab Corporation - Scientific Graphing and Data Analysis Software - 2D graphs, 3D graphs, Contour Plots, Statistical Charts, Data Exploration, Statistics, Curve Fitting, Signal Processing, and Peak Analysis

imgReplaceBg

Contents

Menu Information

Replace Background

Brief Information

Replace background color

Additional Information

This feature is for OriginPro only.

Command Line Usage

1. imgReplaceBg bgl:=100 bgh:=120 adj_b:=-70;

2. imgReplaceBg fuzzi:=22 adj_b:=74 bg:=dark;

3. imgReplaceBg oimg:=<input>;

Variables

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

Input

Image

<active>

Specifies the input image to be manipulated. The default input is the active image.

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.

Low Threshold to Replace bgl

Input

int

100

Specifies the lower threshold value of the color range to be replaced. The value should be an integer between 0 and 255. When the dialog of the X-Function is opened, this value will be automatically initialized according to the auto detected background of the input image.

High Threshold to Replace bgh

Input

int

200

Specifies the higher threshold value of the color range to be replaced. The value should be an integer between 0 and 255. When the dialog of the X-Function is opened, this value will be automatically initialized according to the auto detected background of the input image.

Fuzziness fuzzi

Input

int

50

Specifies the fuzziness value used for determining a color range around the specified color. The colors within this range are similar to the specified color and all of them will be replaced. Note that fuzziness value should be an integer between 1 and 100

Adjust Brightness adj_b

Input

int

50

Specifies the percentage increase/decrease of the brightness for the colors to be replaced. The value should be an integer between -100 and 100. A negative value will cause the brightness to be reduced while a positive value will result in brightness increase.

Background bg

Input

int

bright

Specifies whether or not the background is brighter than the foreground. This is used to initialize the thresholds when the dialog of the X-Function is opened.
Option list

  • dark:Darker than the Foreground
    Choose this option when the background is in general darker than the foreground.
  • bright:Brighter than the Foreground
    Choose this option when the background is in general brighter than the foreground.

Description

This function picks a range of colors to be the background and replace these colors with new ones.

When the dialog of this function is opened, the background of the input image will be automatically detected, and the lower threshold and higher threshold of the background color range can be estimated roughly. The estimates will be used as the initial values for two threshold variables. User can then adjust them to specify the color range to be replaced.

User can opt to replace the colors similar to the specified color with the Fuzziness variable. By doing this, it is more likely to get a smooth output image with a range of color replaced.

Examples

The following example shows you how to change the background color of a sample image myocyte1.tif:

  1. Create a new matrix and import myocyte.tif under \Samples\Image Processing and Analysis folder into it.
  2. Select Image: Arithmetic Transform: Replace Background... from the menu to open the dialog. Change the settings as shown below and click OK.
Image:imgReplaceBg_help_English_files_image002.jpg

The input image is replaced and the background is changed into a very bright color.

Image:imgReplaceBg_help_English_files_image004.jpg
Image:imgReplaceBg_help_English_files_image006.jpg
The original image
The output image


Algorithm

When the dialog of this X-Function is opened, the background of the input image is automatically detected. The detection is based on the histogram of the image: After the computation of the histogram, the peaks on the histogram curve are picked and two tallest peaks are identified. Either of these two peaks is chosen as the background, depending on the Background variable. If Darker than the Foreground is chosen, the peak that corresponds to a lower intensity will be regarded as the peak for the background. Otherwise, the peak that corresponds to a higher intensity will be regarded as the peak for the background. When the peak for the background is chosen, its intensity (x value at its center) will be regarded as the background intensity and the foot markers of this peak will be used to initialize the Low Threshold to Replace variable and the High Threshold to Replace variable.

When this X-Function is executed, the color in the specified color range will be replaced by applying the adjusted brightness to the pixels within the range.

For more information on how the histogram is calculated and how the color is replaced, please refer to the LEADTOOLS Main API Help file, Version 14 and read the L_GetBitmapHistogram and L_ColorReplaceBitmap topics.

References

LEADTOOLS Main API Help file, Version 14

Related X-Functions

imgColorReplace, imgBrightness, imgHistogram