# 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.

## ImageMath Inputs

Parameter | Description
Image 1 | This argument must reference a spreadsheet cell that contains a valid Image data structure. By default, the cell referenced is A1, which contains the Image data structure returned by GetGreyscale.
Image 2 | This argument must reference a spreadsheet cell that contains a valid Image data structure. By default, the cell referenced is A1, which contains the Image data structure returned by GetGreyscale.
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 X | Specifies the x-coordinate (default = 0) where the output image will be displayed, relative to the upper left-hand corner.
Display Y | Specifies the y-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 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.

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).