EasyGauge - Measuring down to Sub-Pixel

Purpose

Note

This section is about the new EasyGauge API. The previous version of the API is described in the Legacy EasyGauge.

EasyGauge can measure and fit various geometrical shapes (rectangles, circles, polygons, wedges, lines and points) to edges in the images.

To find and measure a geometrical shape:

  1. Create a gauge object that corresponds to the required geometrical shape.

  2. Set the nominal shape on the object.

  3. Set the tolerances of the shape.

    • The tolerances express how far away from the nominal shape to search for edge-crossing in the image.

  4. Optionally change the various measurement and fitting parameters.

  5. Call EBaseGauge::Measure .NET Python to perform the measurement and get the measured shape.

    • It throws an exception if the shape cannot be found.

The nominal shape, tolerance, various measurement parameters and the measured shape can be expressed with respect to a reference frame (EFrame .NET Python) given as a parameter to EBaseGauge::Measure .NET Python.

To perform calibrated or metric gauging, use a calibrated reference frame.

Note

The theoretical best-case accuracy is 1/64th pixel for all EasyGauge operators. In practice, you can assume an accuracy of 1/10th pixel.

Gauge Types

Point Gauge

Example of point gauges. On the left, both black to white and white to black transitions are detected. On the right, only black to white transitions are detected.

Line Gauge

../../../_images/linegauge.jpg

Example of a line gauge.

Rectangle Gauge

../../../_images/rectanglegauge.jpg

Example of a rectangle gauge.

Circle Gauge

../../../_images/circlegauge.jpg

Example of a circle gauge.

Wedge Gauge

../../../_images/wedgegauge.jpg

Example of a wedge gauge.

Polygon Gauge

In orange, the closed or open polygon gauge and, in green, the measured transition points

Principles of EasyGauge

Finding Transition Points

All gauges are based on finding the position of all the transition points, called sample points, along a line segment probe, called the sample path, that cross one or several object edges and selecting the most relevant ones.

To do that, EasyGauge extracts the pixel values along the sample path (the red curve) then uses the peak analysis to determine the transition location. All the pixel values in the peak area are used to compute the transition location.

On the left, a measured point on a sample path. On the right, the pixel value profile and its derivate along the sample path.

On a sample path extracted from an image:

  • An edge appears as a transition from dark to light (or vice versa).

  • When plotting the pixel values along the sample path, this transition appears as an S-shaped curve.

  • The first derivative of this curve exhibits a peak around the transition point.

Hint

  • The better the contrast, the sharper the transition and the higher the peak.

  • Sub-pixel accuracy is only possible if the transition is surrounded by almost uniform regions of at least 2 pixels wide.

Measuring Complex Shapes

Except for the point gauge, all gauges try to find and measure complex shapes with the following algorithm:

  1. Place sample paths along the nominal shape at regular interval

  2. Measure each sample path to find sample points on this path.

  3. Select one sample point for each sample path.

  4. Fit the shape to the selected sample points.

    • Fitting the shape means adjusting its parameters to minimize the error residue (average distance of the sample points to the measured shape).

    • The fitting algorithm can include an iterative outlier rejection process, that will reject sample points that may harm the location accuracy:

      1. Apply the model fitting to the valid sample points.

      2. The sample points that are too far away from the fitted model and may harm the location accuracy are made invalid.

      3. Repeat the proccess.

Measurement and Fitting Parameters

Finding Sample Points

All the gauges and ESamplePath .NET Python contain all the point measurement parameters, with default values that detect reasonably contrasted edges:

Transition Strength

The threshold .NET Python level is very important:

  • Too high and significant transitions can be missed and insufficient pixel values can achieve good precision.

  • Too low and noise can cause false transitions.

To resolve this dilemma, the EasyGauge transition selection mechanism can reject low contrast or false edges:

  • The transition strength is measured by the peak amplitude and the area.

  • Every edge measurement determine the peak amplitude and the area.

    • The peak amplitude is the difference between the peak value and the threshold.

    • The peak area is the area under the peak curve and the horizontal line at the threshold value.

  • If either value falls below the minimum amplitude .NET Python or the minimum area .NET Python, the peak is disregarded and no point is assumed at that location.

Transition Type

Select the type of transition to find with SetTransitionType .NET Python:

  • Simple edges:

    Black to white, white to black and indifferent polarities

  • Complex edges:

    ../../../_images/pointlocationbwb.webp

    Complex “Black to white to black” transition type.

    Hint

    You cannot normally detect transitions using the default threshold value (20) as BWB or WBW transitions base the peak analysis on the gray level profile along the sample path and not its first derivative.

Selecting the Most Relevant Transition

There can be multiple transitions that match the transition detection parameters. The parameter SetTransitionChoice .NET Python can be used to select the single most relevant transition. With point gauges, this parameter can have the value ETransitionChoice_All .NET Python, which will return all the transitions matching the other parameter of the detection.

Multiple transitions measured (left) and single transition measured (right).

You can select the single most relevant transition based on 4 criteria:

Best area

The highest peak
ETransitionChoice_LargestAmplitude

Best amplitude

The peak with the largest area
ETransitionChoice_LargestArea

Closest

The peak closest to the gauge center
ETransitionChoice_Closest

3rd from the start

The nth peak encountered
starting from one tip of the gauge (n=3)
ETransitionChoice_NthFromBegin or ETransitionChoice_NthFromEnd

Note

When several peaks have the same value (same area, same amplitude…), the last peak is selected.

Filtering noise

Filtering the image locally can reduce the noise effects.

There are 2 types of filtering:

  • The transverse (lengthwise) filtering averages several parallel lines when sampling the image.

  • The longitudinal (crosswise) uniform filtering can also be applied to the resulting profile curve (SetSmoothing .NET Python)

Configuring Sample Paths

  • Use SetSamplingStep .NET Python to set the spacing between the paths.

  • Use SetTolerance .NET Python to set the length of these paths that is the half-length of the line segment. The tolerance is how far to look for edge crossings around the nominal shape.

    Note

    Note that the EPointGauge .NET Python has no tolerance because it consists in the measurement of edge-crossing on its nominal line.

Point gauge

EasyGauge measurement concepts

Fitting Parameters

Advanced Usage

Analyzing the Results

Tuning the Transition Measurement Parameters for Unclear Transitions

The EasyGauge default parameters and working modes are good for clear transitions.

More complex situations may need the tuning of additional parameters. Here, we show how to tune a point gauge. However, you can apply the same method to the other gauges by analyzing their sample paths.

  1. Set the gauge point location and tolerance.

    • Sets the nominal line of the point gauge. Its center position .NET Python and orientation .NET Python are easy to decide based on a sample image or on the coordinate considerations.

    • The tolerance .NET Python depends on the edge position variations. A larger tolerance increases the likelihood of hitting an edge, but it may be a false edge or an extraneous feature.

    ../../../_images/17836.webp

    Placing the gauge.

  2. Decide whether a noise reduction is required.

    • Lay the gauge over the desired location and observe the profile curve and its derivative (play with the filtering parameters while looking at the plotted curve).

    • The curve regularity gives an indication of the spread of the gray-level values.

    • When these coefficients are set, the gray-level profile will not change anymore.

    ../../../_images/17837.webp

    Filtering noise.

  3. Set the threshold value.

    • Set a value low enough for useful parts of the peaks to cover enough pixels (to achieve better sub-pixel accuracy), but not lower than the ambient image noise.

    ../../../_images/17838.webp

    Thresholding.

  4. Remove weak or false transitions.

    • Use the list of peak amplitudes and areas.

    • Plotting these values along with good and extraneous peaks can help find appropriate peak rejection limits.

    ../../../_images/17839.webp

    Using the amplitude and area to filter out weak or false transitions.

  5. Choose whether all transition points are needed or just the most relevant.

    • If all the transition points are required, you can query them one after the other.

    • Otherwise, choose a point selection strategy based on the strength, the order or the transition polarity (black to white and/or conversely).

    ../../../_images/17840.webp

    Select the relevant transition point.

Display and Graphical Manipulation

Drawing

EBaseGauge::Draw .NET Python gives a graphical representation of the gauge.

Use the enumerate EDrawingMode .NET Python to specify the parts of the gauge that you want to draw:

  • EDrawingMode_Nominal to draw the nominal shape, the gauge tolerances and the handles.

    Point gauge
  • EDrawingMode_Actual to draw the measured shape.

    Point gauge
  • EDrawingMode_Tolerances to draw the tolerances around the nominal shape and its handles.

  • EDrawingMode_TransitionType to draw the transition type of each edge of the shape.

    Point gauge
  • EDrawingMode_SampledPaths to draw the paths sampled along the nominal shape.

  • EDrawingMode_SampledPoints to draw the points measured along each path sampled along the nominal shape that were used to fit the shape.

    Point gauge

    Sampled paths and sampled points

  • EDrawingMode_InvalidSampledPoints to draw the points measured along each path sampled along the nominal shape that were excluded from the shape fitting operation (outliers).

    Point gauge

    Sampled points (green) and invalid sampled points (red)

  • EDrawingMode_PointsInSkipRange to draw the points in the skip ranges for the gauges that support skip ranges.

Graphical Manipulations

../../../_images/tolerance_graphical_manipulation.svg

Handles for the graphical manipulation of the tolerances of the gauge.

Note

With the API, you can perform graphical manipulation on the nominal shape and on the tolerances of the gauge. However, in eVision Studio, only the tolerances can be manipulated in the gauge tools.

Plot

EasyGauge can plot gray-level values along the sample paths and/or its derivative. This is useful to tune the parameters.

Frame

  • When calling the drawing and graphical manipulations methods, pass the frame in which the shape is defined.

  • Also pass the same frame to EBaseGauge::Measure .NET Python.

See also

Have a look at the differences with the old legacy API of EasyGauge and how to port your application to the new API.