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)

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

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

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

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

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

7. Add the ScanExactlyNRidges filter and:

## Used Filters

Icon Name Description
EnumerateImages Emulates image acquisition with images stored on disk.
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.
CreateCoordinateSystemFromSegment Creates a coordinate system with the origin on a given segment.
ScanExactlyNRidges Very fast detection (or presence verification) of thin structures like scratches or scale marks.
RegionMassCenter Computes a point with coordinates equal to the average coordinates of the region's pixels.
SplitRegionIntoBlobs Segmentation of a region into individual objects when the objects do not touch each other.