You are here: Start » Program Examples » Inset Distances

# Inset Distances

## Aim

The task is to devise an algorithm which would compute the distance between ridges.

## Input

The set of images with variable positions of the object as in the picture below:

## Output

Detected ridges in the image with computed distance between them (the width of a gap):

## Hints

As the position of ridges slightly changes, think of a way to locate the ridges without using the Template Matching technique. You could use some other part of the image to find its alignment. Using the Region Analysis it is possible to determine the location of holes and based on this information to create a local coordinate system.

## Solution (AVS)

1. In Workspace Explorer open workspace Examples and in Film strip window select the InsetDistance dataset. Drag the Image channel to the ACQUIRE section.

2. Add the ThresholdToRegion filter. Connect the outImage output from the previous filter to the inImage of the current one. Set the inRoi input as follows:

3. Add the SplitRegionIntoBlobs. Connect the outRegion from the previous filter to the inRegion of the current one. Set the inMaxBlobArea to 1000 so that only smallest blobs are left.

4. Add the RegionMassCenter filter. Connect the outBlobs to the inRegion. Right-click on the outMassCenter output, find the Property Outputs and choose X. It should appear as a new output of the filter.

5. Add the GetSortedElements filter of the Point2D type. Connect the outMassCenter to the inArray and the outMassCenter.X to the inValues. It will sort the blobs according to their X coordinate.

6. Add the CreateCoordinateSystemFromSegment. Right-click on its inSegment input and connect the outElement0 and the outElement1 to the inSegment.Point1 and the inSegment.Point2 respectively.

7. Add the ScanExactlyNRidges filter and:

## Used Filters

Icon Name Description
SplitRegionIntoBlobs Segmentation of a region into individual objects when the objects do not touch each other.
RegionMassCenter Computes a point with coordinates equal to the average coordinates of the region's pixels.
ScanExactlyNRidges Very fast detection (or presence verification) of thin structures like wires or scale marks.
CreateCoordinateSystemFromSegment Creates a coordinate system with the origin on a given segment.
GetSortedElements Returns elements corresponding to 8 smallest/biggest values from the array of values.
ThresholdToRegion Extraction of a region of objects that can be defined by a salient brightness.