ImageMath

A multipurpose function, ImageMath produces a greyscale or black-and-white output image where every pixel is the result of an arithmetic operation—for example, addition, subtraction or averaging—performed between two input images. For more information, see Image.

Note:
  • From In-Sight firmware 5.2.0 and later, the function's algorithm has been changed to use a newer algorithm. Due to this change, the Display Row and Display Column parameters have been added to this function, and the Results Alignment parameter, the Advanced Options parameters and the AND, OR and XOR options (Operation parameter) have been removed from this function.
  • When loading a job containing an ImageMath function configured on the In-Sight firmware 5.1.x or earlier to an In-Sight vision system running firmware version 5.2.0 or later, the Result Alignment parameter and the Advanced Options parameters are automatically removed from the function, and the Display Row parameter and the Display Column parameters are set to the default value (0, 0). If the ImageMath function is configured to use AND, OR or XOR options, the function will return #ERR.
  • When attempting to load a job containing an ImageMath function configured on the In-Sight firmware 5.2.0 or later to an In-Sight vision system running firmware version 5.1.x or earlier, an error message will be displayed and the job load will fail.
  • The ImageMath function configured on the In-Sight firmware 5.1.x or earlier can pass calibration through to any subsequent tools if Image 1 Origin or Image 2 Origin is selected as the Results Alignment option (if Sensor Origin is selected, the results will be in pixels). For more information, see Calibrate Functions. However, the ImageMath function configured on the In-Sight firmware 5.2.0 or later cannot pass through calibration. To convert pixel measurements into real-world coordinates, you have a couple of options.
    • Use the Transform function for the tool (e.g. TransBlobsToWorld). For more information, see TransBlobsToWorld.
    • Pass the ImageMath function through a CalibrateImage function with the desired calibration, and then use the CalibrateImage as an input to the subsequent tools. For more information, see CalibrateImage.

ImageMath Inputs (In-Sight 5.2.0 or Later)

Syntax: ImageMath(Image 1,Image 2,Operation,Display Row,Display Column,Show)

Parameter Description

Image 1

This argument must reference a spreadsheet cell that contains a valid Image data structure. By default, the cell referenced is A0, which contains the Image data structure returned by AcquireImage. For more information, see AcquireImage.

Image 2

This argument must reference a spreadsheet cell that contains a valid Image data structure. By default, the cell referenced is A0, which contains the Image data structure returned by AcquireImage.

Operation

Specifies the image-processing operation that will produce a greyscale or black-and-white output image.

0 = Difference (default)

Absolute value of Image 1 – Image 2. This parameter calculates the difference in greyscale values between Image 1 and Image 2; order of images is irrelevant.

 
Image 1 Image 2   Output Image

1 = Subtract

Image 1 – Image 2. This parameter subtracts the greyscale values of Image 2 from those of Image 1; order of images is relevant.

 
Image 1 Image 2   Output Image

2 = Add

Image 1 + Image 2. This parameter adds the greyscale values of Image 1 and Image 2.

 
Image 1 Image 2   Output Image

3 = Max

Maximum value of Image 1 vs. Image 2. This parameter compares Image 1 and Image 2, and selects the pixel with the highest greyscale value.

4 = Min

Minimum value of Image 1 vs. Image 2. This parameter compares Image 1 and Image 2, and selects the pixel with the lowest greyscale value.

5 = Average

Average value between Image 1 and Image 2. This parameter adds the greyscale values of Image 1 and Image 2, and divides by two.

Display Row

Specifies the Row coordinate (default = 0) where the output image will be displayed, relative to the upper left-hand corner.

Display Column

Specifies the Column coordinate (default = 0) where the output image will be displayed, relative to the upper left-hand corner.

Show

Specifies which graphical overlays are displayed on top of the image.

0 = hide all (default)

The available graphics items will be hidden, except when the cell containing the ImageMath function is highlighted in the spreadsheet.

1 = results graphics only

The processed image will be displayed at all times.

ImageMath Inputs (In-Sight 5.1.x or Earlier)

Syntax: ImageMath(Image 1,Image 2,Operation,Results Alignment,Advanced Options.Divisor,Advanced Options.Greyscale Offset,Show)

Parameter Description

Image 1

This argument must reference a spreadsheet cell that contains a valid Image data structure. By default, the cell referenced is A0, which contains the Image data structure returned by AcquireImage.

Image 2

This argument must reference a spreadsheet cell that contains a valid Image data structure. By default, the cell referenced is A0, which contains the Image data structure returned by AcquireImage.

Operation

Specifies the image-processing operation that will produce a greyscale or black-and-white output image.

0 = Difference (default)

Absolute value of Image 1 – Image 2. This parameter calculates the difference in greyscale values between Image 1 and Image 2; order of images is irrelevant.

1 = Subtract

Image 1 – Image 2. This parameter subtracts the greyscale values of Image 2 from those of Image 1; order of images is relevant.

2 = Add

Image 1 + Image 2. This parameter adds the greyscale values of Image 1 and Image 2.

3 = Max

Maximum value of Image 1 vs. Image 2. This parameter compares Image 1 and Image 2, and selects the pixel with the highest greyscale value.

4 = Min

Minimum value of Image 1 vs. Image 2. This parameter compares Image 1 and Image 2, and selects the pixel with the lowest greyscale value.

5 = Average

Average value between Image 1 and Image 2. This parameter adds the greyscale values of Image 1 and Image 2, and divides by two.

6 = AND

Compares Image 1 and Image 2, and produces a black-and-white image based on the logical "AND" operation. The output pixel is white if both input pixel values are greater than 0, and black if either pixel value is equal to 0.

7 = OR

Compares Image 1 and Image 2, and produces a black-and-white image based on the logical "OR" operation. The output pixel is white if either input pixel value is greater than 0, and black if neither pixel value is greater than 0.

8 = XOR

Compares Image 1 and Image 2, and produces a black-and-white image based on the logical "exclusive OR" operation. The output pixel is white if one input pixel value is greater than 0 and the other is equal to 0, and black if both pixel values are greater than 0 or both are equal to 0.

Results Alignment

Specifies the location of the output image after it has undergone the image-processing operation.

0 = Image 1 Origin (default)

Specifies Image 1 as the origin location of the output image; the resulting image overlays Image 1.

1 = Image 2 Origin

Specifies Image 2 as the origin location of the output image; the resulting image overlays Image 2.

2 = Sensor Origin

Specifies Row 0, Column 0 of AcquireImage as the origin location of the output image; the resulting image is placed in the top-left corner of the image.

Advanced Options

Specifies the additional mathematical modifications that can be applied to a greyscale output image. The order of operation is (1) divide and (2) offset.

Divisor

Specifies the value to divide into each output pixel's greyscale value. (default = 1) This changes the intensity of the pixel values, and can be used to "scale down" pixel values that exceed 255.

Greyscale Offset

Specifies an offset value to apply to each output pixel's greyscale value. (default = 0) Negative and positive offsets decrease and increase, respectively, the brightness of the output.

Show

Specifies which graphical overlays are displayed on top of the image.

0 = hide all (default)

The available graphics items will be hidden, except when the cell containing the ImageMath function is highlighted in the spreadsheet.

1 = results graphics only

The processed image will be displayed at all times.

ImageMath Outputs

Returns

An Image data structure containing the processed image, or #ERR if any of the input parameters are invalid.

ImageMath Example

In this example, the goal is to produce an output file of only the holes in a gasket. Later, the holes will be referenced by another tool so that decisions can be made regarding the holes.

For Image 1, the user acquires an image of the complete gasket (below).

The user would like Image 2 to be a copy of Image 1, but with all the white holes filled. To produce this, the user inserts the Filter function into the spreadsheet and, in the property sheet, maximizes the ROI by selecting the word "Region" and clicking the Maximize Region button in the property sheet's toolbar. Maximizing the ROI ensures that the ROIs of Image 1 and Images 2 are the same size. For more information, see Filter.

Selecting "Fill Light Holes" from the Operation pull-down menu, accepting the default settings of the other parameters and clicking OK in the Filter property sheet completes the configuration for this example and applies the function to the input image (see result, below).

The user then inserts the ImageMath function into the spreadsheet and, in the property sheet, accepts A0 as Image 1. Now, the Filter output image must be referenced as the source for Image 2. The user double-clicks on the words "Image 2" in the property sheet, which disappears to reveal the In-Sight spreadsheet. The user clicks on the Image data structure returned by Filter and clicks the OK button on the Job Edit toolbar to confirm the selection and return to the ImageMath property sheet. (The selection can also be confirmed by pressing the Enter key or by double-clicking on the Image data structure.)

Selecting "Differences" from the Operation pull-down menu, accepting the default settings of the other parameters and clicking OK in the ImageMath property sheet completes the configuration for this example and applies the function to the input image.

The result is an output image of only the holes in the gasket (below).