ComputeImageSharpness

ComputeImageSharpness computes a measure of the relative focus of an input image as part of an iterative process for refocusing an In-Sight vision system lens.

ComputeImageSharpness Overview

Called the image sharpness score, this measure indicates the degree to which the image, or a region of interest (ROI), includes the smallest resolvable features in a "scene" (that is, the object and its background as captured in the image).

Operation is simple - an image is acquired, and the ComputeImageSharpness tool obtains the image sharpness score. Then, the lens is refocused, nothing else is changed within the scene and a new image is acquired and scored. The higher the score, the sharper the focus. This process is repeated until the focus is acceptable to the user.

Note: A single image sharpness score conveys no useful information about the absolute sharpness of an image; it must be compared with another image sharpness score from the same, exact scene. The scenes must be identical.

ComputeImageSharpness Inputs

Syntax: ComputeImageSharpness(Image,Fixture.Row,Fixture.Column,Fixture.Theta,Region.X,Region.Y,Region.High,Region.Wide,Region.Angle,Region.Curve,Operation,Smoothness,Show)

Parameter Description

Image

This parameter must reference a spreadsheet cell that contains an Image data structure. By default, this parameter references A0, the cell containing the AcquireImage Image data structure. This parameter can also reference other Image data structures, such as those returned by the Vision Tool Image functions. For more information, see AcquireImage and Image.

Fixture

Defines the Region of Interest (ROI) relative to a Fixture input or the output of a Vision Tool function's image coordinate system. Setting the ROI relative to a Fixture ensures that if the Fixture is rotated or translated, the ROI will be rotated or translated in relation to the Fixture. For more information, see Fixture and Vision Tools Functions.

The default setting is (0,0,0), the top leftmost corner of the image.

Row

The row offset, in image coordinates.

Column

The column offset, in image coordinates.

Theta

The angle of orientation, in the image coordinate system.

Region

The Region of Interest (ROI) specifies the region of the image that undergoes analysis and creates a rectangular image region that can be transformed and rotated. For more information, see Interactive Graphics Mode.

Tip: With this parameter selected, you can press the Maximize Region button on the property sheet's toolbar to maximize the region and cover the entire image.

X

The x-offset of the origin, in fixture coordinates.

Y

The y-offset of the origin, in fixture coordinates.

High

The dimension along the region's x-axis.

Wide

The dimension along the region's y-axis.

Angle

The orientation, in fixture coordinates.

Operation

Gradient Energy: Computes image sharpness based on the energy in the local grey-level gradient of the image or the ROI. The local grey-level gradient represents the rate of change in greyscale values for a given area. An abrupt change in greyscale results in a large magnitude in the grey-level gradient and a higher image sharpness scare.

Smoothness

Specifies an image-smoothing operation to help eliminate high-frequency noise that might be present in the ROI. There are three settings:

0 = None (default)

No smoothing takes place; provides the fastest performance.

1 = Smoothing Level 1

A degree of smoothing is applied to the ROI; eliminates very-high-frequency noise in the ROI.

2 = Smoothing Level 2

A further degree of smoothing is applied to the ROI; eliminates high-frequency and very-high-frequency noise in the ROI.

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 ComputeImageSharpness function is highlighted in the spreadsheet.

1 = input graphics only

The graphics items associated with the input image region will be displayed at all times.

ComputeImageSharpness Outputs

Returns

An image sharpness score as a floating point value, or #ERR if any of the input parameters are invalid.

ComputeImageSharpness Example

In this example, the object in the input image is a Cognex vision system.

  1. Adjust the lens focus in Live Video mode, which is entered clicking the Live Video button on the Job Display toolbar and exited either by pressing any key on the keyboard or by clicking the Live Video button again.
  2. After exiting Live Video mode, the insert the function into the In-Sight spreadsheet and defines the ROI by double-clicking on the word "Region" in the property sheet, which disappears to reveal the red ROI box overlaid on the image.
  3. Move and resize the box using the cursor, and click the OK button on the Job Edit toolbar to confirm the selection and return to the property sheet. (The selection can also be confirmed by pressing the Enter key or by double-clicking within the ROI.)
  4. 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 two images below show a blurry image of the Cognex vision system and an Overlay view indicating that the image sharpness score is 3.317.

    After adjusting the focus on the lens in Live Video mode, the image is less blurry. Exit Live Video mode and view the new image sharpness score of 8.107:

    Because the image is still blurry, you will need to continue adjusting the focus in Live Video mode and comparing the image sharpness scores until the object is in sharp focus. If the focus remains inadequate, you might need to change the lens, the distance between the lens and the object or some other hardware parameter.