2.6.3.7 imgSimpleMath(Pro)
Menu Information
Image: Arithmetic Transform: Simple Math
Brief Information
Perform simple math operations between two images
Additional Information
This feature is for OriginPro only.
Command Line Usage
1. imgSimpleMath img2:=[blue]1!mat(1);
2. imgSimpleMath img1:=[mbook1]msheet1!mat(1) img2:=[mbook2]msheet1!mat(1);
3. imgSimpleMath c1:=green f1:=10 img2:= [mbook2]msheet1!mat(1) c2:=green f2:=2 func:=xor oimg:=result;
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
|
img1
|
Input
Image
|
<active>
|
Specifies the first input image (Image1). The default input is the active image.
|
Channel of Image1
|
c1
|
Input
int
|
master
|
Specifies the channel of Image1, on which the function will be operated. The default is all.
Option list
- master:Master
- All channels
- red:Red
- Red channel
- green:Green
- Green channel
- blue:Blue
- Blue channel
|
Factor *Image1
|
f1
|
Input
double
|
1.0
|
Specifies a factor, by which image1 will be first multiplied before the math operation. The default factor is 1.0.
|
Offset Z of Image1
|
z1
|
Input
int
|
0
|
Specifies a constant, by which image1 will be added after it is multiplied the factor and before the math operation.
|
Input Matrix
|
img2
|
Input
Image
|
<>
|
Specifies the second input image (Image2), with which the first image will be combined.
|
Channel of Image2
|
c2
|
Input
int
|
master
|
Specifies the channel of Image2, on which the function will be operated. The default is all.
Option list
- master:Master
- All channels
- red:Red
- Red channel
- green:Green
- Green channel
- Blue
- Blue channel
|
Factor * Image2
|
f2
|
Input
double
|
1.0
|
Specifies a factor, by which image2 will be first multiplied before the math operation. The default factor is 1.0.
|
Math Function
|
func
|
Input
int
|
and
|
Specifies the math function used to combine two images.
Option list
- and:And
- Combines each pair of corresponding pixels, using a bitwise AND (&) operation.
- or:Or
- Combines each pair of corresponding pixels, using a bitwise OR ( | ) operation.
- xor:Xor
- Combines each pair of corresponding pixels, using a bitwise exclusive OR (^) operation.
- add:Add
- Adds each pair of corresponding pixels.
- sub12:img1 - img2
- Subtracts image2 from image1.
- sub21:img2 - img1
- Subtracts image1 from image2.
- mul:img2 * img1
- Multiplies each pair of corresponding pixels. If the result exceeds the maximum value (2^bpp-1, where bpp is the bits per pixel), the result will be divided by the maximum value.
- div12:img1/img2
- Divides image1 by image2. If image2 > 0, then the result is calculated as follows: result = min( (img1/ img2) * 255, 255 ). Otherwise, if image2 = 0, then result = 255.
- div21:img2/img1
- Divides image2 by image1. If image1 > 0, then the result is calculated as follows: result = min( (img2/ img1) * 255, 255 ). Otherwise, if image1 = 0, then result = 255.
- avg:avg (img2,img1)
- Uses the average of the two values.
- min:min(img2,img1)
- Uses the lesser of the two values
- max:max(img2,img1)
- Uses the greater of the two values.
- abs:abs(img2 - img1)
- Calculates the absolute difference between the two values.
|
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.
|
Offset X
|
x
|
Input
int
|
0
|
Specifies the horizontal offset for Image2. A non-zero value will cause the relative position of two images to be changed.
|
Offset Y
|
y
|
Input
int
|
0
|
Specifies the vertical offset for Image2. A non-zero value will cause the relative position of two images to be changed.
|
Crop to Common Area
|
crop
|
Input
int
|
0
|
Specifies whether to crop the output to the common area of two input images.
|
Description
The imgSimpleMath function combines data from two images, using the specified mathematic function.
Examples
// Subtract background from a cell image then detect the cell edges.
//Create a new folder in the Project Explorer
pe_mkdir EdgeDetection path:=aa$;
pe_cd aa$;
//Create a matrix and import the cell image into it
window -t m;
fname$ = System.path.program$ +"samples\Image Processing and Analysis\cell.jpg";
impimage;
CellBk$ = %h;
//Create a matrix and import the background image into it
window -t m;
fname$ = System.path.program$ +"samples\Image Processing and Analysis\bgnd.jpg";
impimage;
//Subtract background and pre-processing
imgSimpleMath img2:=cellbk$ func:=4 x:=7 y:=13 crop:=1;
imgBinary t1:=65 t2:=255;
imgMedian d:=18;
//Edge detection
imgEdge t:=12 f:=shv;
//Add the edges back to the cell image
imgSimpleMath img2:=cellbk$ func:=3;
window -z; //Maximize window
Algorithm
The imgSimpleMath function combines the data byte-by-byte using specified math function. The computation mainly uses L_CombineBitmapExt() function from LEADTOOLS Main API. Please refer to the LEADTOOLS Main API Help file, Version 14 and read the L_CombineBitmapExt topic.
References
LEADTOOLS Main API Help file, Version 14
Related X-Functions
imgBlend
|