
Contents |
Replace Background
Replace background color
This feature is for OriginPro only.
1. imgReplaceBg bgl:=100 bgh:=120 adj_b:=-70;
2. imgReplaceBg fuzzi:=22 adj_b:=74 bg:=dark;
3. imgReplaceBg oimg:=<input>;
| Display Name | Variable Name | I/O and Type | Default Value | Description |
|---|---|---|---|---|
| Input Matrix | img |
Input Image | |
Specifies the input image to be manipulated. The default input is the active image. |
| Output Image | oimg |
Output Image | |
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 | |
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 | |
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 | |
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 | |
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 | |
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.
|
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.
The following example shows you how to change the background color of a sample image myocyte1.tif:
The input image is replaced and the background is changed into a very bright color.
![]() |
![]() |
|
|
|
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.
LEADTOOLS Main API Help file, Version 14