2.6.3.6 imgReplaceBg(Pro)
Menu Information
Image: Arithmetic Transform: Replace Background
Brief Information
Replace background color of image
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>;
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 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 in OriginPro picks a range of intensities to be the background and replace these intensities with new ones.
The background is the range of intensities between the lower threshold and the higher threshold, which can be automatically detected by analyzing the histogram of the image or be estimated roughly by the user. When the dialog of this function is opened, the lower and higher threshold of the background intensities range can be estimated roughly, and 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.
In addition, user can opt to replace other intensities similar to the specified background intensities with the Fuzziness variable. With this feature, it is more likely to obtain a smooth output image. When this X-Function is executed, the intensities in the background will be replaced by adjusting their value of brightness with the variable Adjust Brightness.
Examples
The following example shows you how a background was replaced by a background roughly estimated by the user.
- Create a new matrix and import myocyte.tif under \Samples\Image Processing and Analysis folder into it.
- Select Image: Arithmetic Transform: Replace Background... from the menu to open the dialog. Change the settings as shown below and click OK.
The input image is replaced and the background is changed into a very bright color.
|
|
The original image
|
The output image
|
Note: OriginPro includes the ability to automatically recalculate the analysis result of the Replace Background operation 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
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
|