# ImageMath

A multipurpose function, ImageMath produces a greyscale or black-and-white output image where every pixel is the result of an arithmetic operation, such as addition, subtraction, or averaging, performed between two input images.

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 produces 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. The 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. The 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 are hidden, except when the cell containing the ImageMath function is highlighted in the spreadsheet.
1 = results graphics only | The processed image is displayed at all times.

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 are referenced by another tool so that decisions can be made regarding the holes.

1. Acquire an image of the complete gasket.

2. Create an Image 2 to be a copy of Image 1, but with all the white holes filled. To produce this, insert the Filter function into the spreadsheet.

3. Maximize the ROI in the property sheet by selecting the word Region and clicking the Maximize Region button in the toolbar of the property sheet. Maximizing the ROI ensures that the ROIs of Image 1 and Images 2 are the same size.

4. Select Fill Light Holes from the Operation dropdown menu.

5. Accept the default settings of the other parameters and click OK in the Filter property sheet to complete the configuration and apply the function to the input image.

6. Insert the ImageMath function into the spreadsheet.

7. Accept A1 as Image 1 in the property sheet. Now, the Filter output image must be referenced as the source for Image 2.

8. Double-click on Image 2 in the property sheet, which disappears to reveal the In-Sight Spreadsheet spreadsheet.

9. Click the Image data structure returned by Filter.

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

11. Select Differences from the Operation dropdown menu.

12. Accept the default settings of the other parameters and click OK in the property sheet to complete the configuration for this example and apply the function to the input image. The result is an output image of only the holes in the gasket.