Back to Adaptive Vision Library website

# FitSegmentToEdges_Direct

Header: AVL.h avl MetrologyPro

Performs a series of 1D edge detections and finds a segment that best matches the detected points.

Applications: Precise detection of a straight edge, whose rough location is known beforehand.

### Syntax

C++
C#

void avl::FitSegmentToEdges_Direct
(
const avl::Image& inImage,
const avl::SegmentFittingField& inFittingField,
atl::Optional<const avl::CoordinateSystem2D&> inFittingFieldAlignment,
int inScanCount,
int inScanWidth,
const avl::SamplingParams& inSamplingParams,
const avl::EdgeScanParams& inEdgeScanParams,
avl::Selection::Type inEdgeSelection,
atl::Optional<const avl::LocalBlindness&> inLocalBlindness,
float inMaxIncompleteness,
atl::Optional<avl::LineMEstimator::Type> inOutlierSuppression,
atl::Conditional<avl::Segment2D>& outSegment,
atl::Optional<atl::Array<atl::Conditional<avl::Edge1D>>&> outEdges = atl::NIL,
atl::Optional<atl::Conditional<avl::Profile>&> outDeviationProfile = atl::NIL,
atl::Optional<avl::SegmentFittingField&> outAlignedFittingField = atl::NIL,
atl::Optional<atl::Array<avl::Point2D>&> outInliers = atl::NIL,
atl::Array<avl::Segment2D>& diagScanSegments,
atl::Array<avl::Rectangle2D>& diagSamplingAreas,
atl::Array<avl::Profile>& diagBrightnessProfiles,
atl::Array<avl::Profile>& diagResponseProfiles
)


### Parameters

Name Type Range Default Description
inImage const Image& Image to fit segment to
inFittingField const SegmentFittingField& Segment fitting field
inFittingFieldAlignment Optional<const CoordinateSystem2D&> NIL Adjusts the fitting field to the position of the inspected object
inScanCount int 3 - 10 The number of points that will be searched to estimate the position of the segment
inScanWidth int 1 - 5 The width of each scan field (in pixels)
inSamplingParams const SamplingParams& Parameters controlling the sampling process
inEdgeScanParams const EdgeScanParams& EdgeScanParams ( ProfileInterpolation: Quadratic4 SmoothingStdDev: 1.0f MinMagnitude: 5.0f EdgeTransition: BrightToDark ) Parameters controlling the edge extraction process
inEdgeSelection Selection::Type Selection mode of edges
inLocalBlindness Optional<const LocalBlindness&> NIL Defines conditions in which weaker edges can be detected in the vicinity of stronger edges
inMaxIncompleteness float 0.0 - 0.999 0.1f Maximal fraction of edge points not found
inOutlierSuppression Optional<LineMEstimator::Type> NIL Selects a method for ignoring incorrectly detected points
outSegment Conditional<Segment2D>& Fitted segment or nothing if the fitting fails
outEdges Optional<Array<Conditional<Edge1D>>&> NIL Found edges
outDeviationProfile Optional<Conditional<Profile>&> NIL Profile of distances between the actual segment points and the corresponding reference segment points
outAlignedFittingField Optional<SegmentFittingField&> NIL Fitting field used; in the image coordinate system
outInliers Optional<Array<Point2D>&> NIL Points matching the fitting segment
diagScanSegments Array<Segment2D>& Segments along which the scans were run
diagSamplingAreas Array<Rectangle2D>& Areas from which the input image is sampled
diagBrightnessProfiles Array<Profile>& Extracted image profiles
diagResponseProfiles Array<Profile>& Profiles of the edge (derivative) operator response

### Optional Outputs

The computation of following outputs can be switched off by passing value atl::NIL to these parameters: outEdges, outDeviationProfile, outAlignedFittingField, outInliers.

### Description

The operation tries to fit a given segment to edges present in the inImage image. Internally, it performs a series of scans with the ScanSingleEdge_Direct filter along inScanCount specific scan segments which length is always equal to the inFittingField width and cannot be less than 4. The found points are then used to determine the actual position of the segment in the image. Only inMaxIncompleteness fraction of these scans may fail. If the fitting according to the given parameters is not possible, outSegment is set to Nil.

### Hints

• Connect an input image to the inImage input.
• Define inEdgeScanParams.EdgeTransition to detect a particular edge type, and only that type.
• If no or too few edge points are found, try decreasing inEdgeScanParams.MinMagnitude.
• If some of the scans may fail, set the inMaxIncompleteness input accordingly.
• If some of the scans may produce false results, try different values of the inOutlierSuppression input.
• Use the outEdges outputs to visualize the scanning results.

### Examples

Fitting two segments to the edges of a blister
(inEdgeScanParams.EdgeTransition = DarkToBright, inEdgeScanParams.SmoothingStdDev = 1.0).

### Remarks

Read more about Local Coordinate Systems in Machine Vision Guide: Local Coordinate Systems.

This filter is a part of the Shape Fitting toolset. To read more about this technique, one can refer to the Shape Fitting chapter of our Machine Vision Guide

### Hardware Acceleration

This operation supports automatic parallelization for multicore and multiprocessor systems.