HALCON Reference Manual 10.0.2
Table of Contents / XLD / Features ClassesClassesClasses | | | Operators

fit_line_contour_xldfit_line_contour_xldfit_line_contour_xldFitLineContourXldFitLineContourXld (Operator)

Name

fit_line_contour_xldfit_line_contour_xldfit_line_contour_xldFitLineContourXldFitLineContourXld — Approximate XLD contours by line segments.

Signature

fit_line_contour_xld(Contours : : Algorithm, MaxNumPoints, ClippingEndPoints, Iterations, ClippingFactor : RowBegin, ColBegin, RowEnd, ColEnd, Nr, Nc, Dist)

Herror fit_line_contour_xld(const Hobject Contours, const char* Algorithm, const Hlong MaxNumPoints, const Hlong ClippingEndPoints, const Hlong Iterations, double ClippingFactor, double* RowBegin, double* ColBegin, double* RowEnd, double* ColEnd, double* Nr, double* Nc, double* Dist)

Herror T_fit_line_contour_xld(const Hobject Contours, const Htuple Algorithm, const Htuple MaxNumPoints, const Htuple ClippingEndPoints, const Htuple Iterations, const Htuple ClippingFactor, Htuple* RowBegin, Htuple* ColBegin, Htuple* RowEnd, Htuple* ColEnd, Htuple* Nr, Htuple* Nc, Htuple* Dist)

Herror fit_line_contour_xld(Hobject Contours, const HTuple& Algorithm, const HTuple& MaxNumPoints, const HTuple& ClippingEndPoints, const HTuple& Iterations, const HTuple& ClippingFactor, double* RowBegin, double* ColBegin, double* RowEnd, double* ColEnd, double* Nr, double* Nc, double* Dist)

Herror fit_line_contour_xld(Hobject Contours, const HTuple& Algorithm, const HTuple& MaxNumPoints, const HTuple& ClippingEndPoints, const HTuple& Iterations, const HTuple& ClippingFactor, HTuple* RowBegin, HTuple* ColBegin, HTuple* RowEnd, HTuple* ColEnd, HTuple* Nr, HTuple* Nc, HTuple* Dist)

double HXLDCont::FitLineContourXld(const HTuple& Algorithm, const HTuple& MaxNumPoints, const HTuple& ClippingEndPoints, const HTuple& Iterations, const HTuple& ClippingFactor, double* ColBegin, double* RowEnd, double* ColEnd, double* Nr, double* Nc, double* Dist) const

HTuple HXLDContArray::FitLineContourXld(const HTuple& Algorithm, const HTuple& MaxNumPoints, const HTuple& ClippingEndPoints, const HTuple& Iterations, const HTuple& ClippingFactor, HTuple* ColBegin, HTuple* RowEnd, HTuple* ColEnd, HTuple* Nr, HTuple* Nc, HTuple* Dist) const

void HOperatorSetX.FitLineContourXld(
[in] IHUntypedObjectX* Contours, [in] VARIANT Algorithm, [in] VARIANT MaxNumPoints, [in] VARIANT ClippingEndPoints, [in] VARIANT Iterations, [in] VARIANT ClippingFactor, [out] VARIANT* RowBegin, [out] VARIANT* ColBegin, [out] VARIANT* RowEnd, [out] VARIANT* ColEnd, [out] VARIANT* Nr, [out] VARIANT* Nc, [out] VARIANT* Dist)

VARIANT HXLDContX.FitLineContourXld(
[in] BSTR Algorithm, [in] Hlong MaxNumPoints, [in] Hlong ClippingEndPoints, [in] Hlong Iterations, [in] double ClippingFactor, [out] VARIANT* ColBegin, [out] VARIANT* RowEnd, [out] VARIANT* ColEnd, [out] VARIANT* Nr, [out] VARIANT* Nc, [out] VARIANT* Dist)

static void HOperatorSet.FitLineContourXld(HObject contours, HTuple algorithm, HTuple maxNumPoints, HTuple clippingEndPoints, HTuple iterations, HTuple clippingFactor, out HTuple rowBegin, out HTuple colBegin, out HTuple rowEnd, out HTuple colEnd, out HTuple nr, out HTuple nc, out HTuple dist)

void HXLDCont.FitLineContourXld(string algorithm, int maxNumPoints, int clippingEndPoints, int iterations, double clippingFactor, out HTuple rowBegin, out HTuple colBegin, out HTuple rowEnd, out HTuple colEnd, out HTuple nr, out HTuple nc, out HTuple dist)

void HXLDCont.FitLineContourXld(string algorithm, int maxNumPoints, int clippingEndPoints, int iterations, double clippingFactor, out double rowBegin, out double colBegin, out double rowEnd, out double colEnd, out double nr, out double nc, out double dist)

Description

fit_line_contour_xldfit_line_contour_xldfit_line_contour_xldFitLineContourXldFitLineContourXld approximates the XLD contours ContoursContoursContoursContourscontours by line segments. It does not perform a segmentation of the input contours. Thus, one has to make sure that each contour corresponds to one and only one line segment. The operator returns for each contour the start point (RowBeginRowBeginRowBeginRowBeginrowBegin, ColBeginColBeginColBeginColBegincolBegin), the end point (RowEndRowEndRowEndRowEndrowEnd, ColEndColEndColEndColEndcolEnd), and the regression line to the contour given by the normal vector (NrNrNrNrnr, NcNcNcNcnc) of the line and its distance DistDistDistDistdist from the origin, i.e., the line equation is given by r *NrNrNrNrnr + c * NcNcNcNcnc - DistDistDistDistdist = 0 .

The algorithm used for the fitting of lines can be selected via AlgorithmAlgorithmAlgorithmAlgorithmalgorithm:

'regression'"regression""regression""regression""regression":

Standard 'least squares' line fitting.

'huber'"huber""huber""huber""huber":

Weighted 'least squares' line fitting, where the impact of outliers is decreased based on the approach of Huber (see below).

'tukey'"tukey""tukey""tukey""tukey":

Weighted 'least squares' line fitting, where the impact of outliers is decreased based on the approach of Tukey (see below).

'drop'"drop""drop""drop""drop":

Weighted 'least squares' line fitting, where outliers are eliminated. In particular, all contour points further away from the contour than the mean distance to the regression line multiplied with the ClippingFactorClippingFactorClippingFactorClippingFactorclippingFactor (see below) are ignored for the calculation of the undistorted regression line.

'gauss'"gauss""gauss""gauss""gauss":

Weighted 'least squares' line fitting, where the impact of outliers is decreased based on the mean value and the standard deviation of the distances of all contour points from the approximating line.

For 'huber', 'tukey', and 'drop' a robust error statistics is used to estimate the standard deviation of the distances from the contour points without outliers from the approximating line. The parameter ClippingFactorClippingFactorClippingFactorClippingFactorclippingFactor (a scaling factor for the standard deviation) controls the amount of damping outliers: The smaller the value chosen for ClippingFactorClippingFactorClippingFactorClippingFactorclippingFactor the more outliers are detected. The detection of outliers is repeated. The parameter IterationsIterationsIterationsIterationsiterations specifies the number of iterations. In the modus 'regression' this value is ignored. Note that in the approach of Tukey ('tukey'), the outliers are removed before performing the approximation and all other points are weighted, whereas in the approach of Huber ('huber'), the outliers still have a small influence. Particularly, for outliers the optimization is influenced linearly and for points with a smaller distance it is influenced quadratically. In practice, the approach of Tukey is recommended.

To reduce the computational load, the fitting of lines can be restricted to a subset of the contour points: If a value other than -1 is assigned to MaxNumPointsMaxNumPointsMaxNumPointsMaxNumPointsmaxNumPoints, only up to MaxNumPointsMaxNumPointsMaxNumPointsMaxNumPointsmaxNumPoints points - uniformly distributed over the contour - are used.

The start point and the end point of a line segment is determined by projecting the first and the last point of the corresponding contour to the approximating line. Due to artefacts in the pre-processing the start and end points of a contour might be faulty. Therefore, it is possible to exclude ClippingEndPointsClippingEndPointsClippingEndPointsClippingEndPointsclippingEndPoints points at the beginning and at the end of a contour from the line fitting. However, they are still used for the determination of the start point and the end point of the line segment.

The minimun necessary number of contour points for fitting a line is two. Therefore, it is required that the number of contour points is at least 2 + 2*ClippingEndPointsClippingEndPointsClippingEndPointsClippingEndPointsclippingEndPoints .

Parallelization

Parameters

ContoursContoursContoursContourscontours (input_object)  xld_cont(-array) objectHXLDContHXLDContHXLDContXHobject

Input contours.

AlgorithmAlgorithmAlgorithmAlgorithmalgorithm (input_control)  string HTupleHTupleVARIANTHtuple (string) (string) (char*) (BSTR) (char*)

Algorithm for the fitting of lines.

Default value: 'tukey' "tukey" "tukey" "tukey" "tukey"

List of values: 'regression'"regression""regression""regression""regression", 'huber'"huber""huber""huber""huber", 'tukey'"tukey""tukey""tukey""tukey", 'gauss'"gauss""gauss""gauss""gauss", 'drop'"drop""drop""drop""drop"

MaxNumPointsMaxNumPointsMaxNumPointsMaxNumPointsmaxNumPoints (input_control)  integer HTupleHTupleVARIANTHtuple (integer) (int / long) (Hlong) (Hlong) (Hlong)

Maximum number of contour points used for the computation (-1 for all points).

Default value: -1

Restriction: MaxNumPoints >= 2

ClippingEndPointsClippingEndPointsClippingEndPointsClippingEndPointsclippingEndPoints (input_control)  integer HTupleHTupleVARIANTHtuple (integer) (int / long) (Hlong) (Hlong) (Hlong)

Number of points at the beginning and at the end of the contours to be ignored for the fitting.

Default value: 0

Restriction: ClippingEndPoints >= 0

IterationsIterationsIterationsIterationsiterations (input_control)  integer HTupleHTupleVARIANTHtuple (integer) (int / long) (Hlong) (Hlong) (Hlong)

Maximum number of iterations (unused for 'regression').

Default value: 5

Restriction: Iterations >= 0

ClippingFactorClippingFactorClippingFactorClippingFactorclippingFactor (input_control)  real HTupleHTupleVARIANTHtuple (real) (double) (double) (double) (double)

Clipping factor for the elimination of outliers (typical: 1.0 for 'huber' and 'drop' and 2.0 for 'tukey').

Default value: 2.0

List of values: 1.0, 1.5, 2.0, 2.5, 3.0

Restriction: ClippingFactor > 0

RowBeginRowBeginRowBeginRowBeginrowBegin (output_control)  line.begin.y(-array) HTupleHTupleVARIANTHtuple (real) (double) (double) (double) (double)

Row coordinates of the starting points of the line segments.

ColBeginColBeginColBeginColBegincolBegin (output_control)  line.begin.x(-array) HTupleHTupleVARIANTHtuple (real) (double) (double) (double) (double)

Column coordinates of the starting points of the line segments.

RowEndRowEndRowEndRowEndrowEnd (output_control)  line.end.y(-array) HTupleHTupleVARIANTHtuple (real) (double) (double) (double) (double)

Row coordinates of the end points of the line segments.

ColEndColEndColEndColEndcolEnd (output_control)  line.end.x(-array) HTupleHTupleVARIANTHtuple (real) (double) (double) (double) (double)

Column coordinates of the end points of the line segments.

NrNrNrNrnr (output_control)  number(-array) HTupleHTupleVARIANTHtuple (real) (double) (double) (double) (double)

Line parameter: Row coordinate of the normal vector

NcNcNcNcnc (output_control)  number(-array) HTupleHTupleVARIANTHtuple (real) (double) (double) (double) (double)

Line parameter: Column coordinate of the normal vector

DistDistDistDistdist (output_control)  number(-array) HTupleHTupleVARIANTHtuple (real) (double) (double) (double) (double)

Line parameter: Distance of the line from the origin

Example (HDevelop)

read_image (Image, 'mreut')
edges_sub_pix (Image, Edges, 'lanser2', 0.5, 20, 40)
gen_polygons_xld (Edges, Polygons, 'ramer', 2)
split_contours_xld (Polygons, Contours, 'polygon', 1, 5)
fit_line_contour_xld (Contours, 'regression', -1, 0, 5, 2, RowBegin, \
                      ColBegin, RowEnd, ColEnd, Nr, Nc, Dist)

Example (HDevelop)

read_image (Image, 'mreut')
edges_sub_pix (Image, Edges, 'lanser2', 0.5, 20, 40)
gen_polygons_xld (Edges, Polygons, 'ramer', 2)
split_contours_xld (Polygons, Contours, 'polygon', 1, 5)
fit_line_contour_xld (Contours, 'regression', -1, 0, 5, 2, RowBegin, \
                      ColBegin, RowEnd, ColEnd, Nr, Nc, Dist)

Example (C++)

read_image (Image, 'mreut');
edges_sub_pix (Image, Edges, 'lanser2', 0.5, 20, 40);
gen_polygons_xld (Edges, Polygons, 'ramer', 2);
split_contours_xld (Polygons, Contours, 'polygon', 1, 5);
fit_line_contour_xld (Contours, 'regression', -1, 0, 5, 2, RowBegin,
                      ColBegin, RowEnd, ColEnd, Nr, Nc, Dist);

Example (HDevelop)

read_image (Image, 'mreut')
edges_sub_pix (Image, Edges, 'lanser2', 0.5, 20, 40)
gen_polygons_xld (Edges, Polygons, 'ramer', 2)
split_contours_xld (Polygons, Contours, 'polygon', 1, 5)
fit_line_contour_xld (Contours, 'regression', -1, 0, 5, 2, RowBegin, \
                      ColBegin, RowEnd, ColEnd, Nr, Nc, Dist)

Example (HDevelop)

read_image (Image, 'mreut')
edges_sub_pix (Image, Edges, 'lanser2', 0.5, 20, 40)
gen_polygons_xld (Edges, Polygons, 'ramer', 2)
split_contours_xld (Polygons, Contours, 'polygon', 1, 5)
fit_line_contour_xld (Contours, 'regression', -1, 0, 5, 2, RowBegin, \
                      ColBegin, RowEnd, ColEnd, Nr, Nc, Dist)

Result

fit_line_contour_xldfit_line_contour_xldfit_line_contour_xldFitLineContourXldFitLineContourXld returns 2 (H_MSG_TRUE) if all parameter values are correct, and line segments could be fitted to the input contours. If the input is empty the behaviour can be set via set_system('no_object_result',<Result>)set_system("no_object_result",<Result>)set_system("no_object_result",<Result>)SetSystem("no_object_result",<Result>)SetSystem("no_object_result",<Result>). If necessary, an exception is raised. If the parameter ClippingFactorClippingFactorClippingFactorClippingFactorclippingFactor is chosen too small, i.e., all points are classified as outliers, the error 3264 is raised.

Possible Predecessors

gen_contours_skeleton_xldgen_contours_skeleton_xldgen_contours_skeleton_xldGenContoursSkeletonXldGenContoursSkeletonXld, lines_gausslines_gausslines_gaussLinesGaussLinesGauss, lines_facetlines_facetlines_facetLinesFacetLinesFacet, edges_sub_pixedges_sub_pixedges_sub_pixEdgesSubPixEdgesSubPix, smooth_contours_xldsmooth_contours_xldsmooth_contours_xldSmoothContoursXldSmoothContoursXld

Possible Successors

disp_linedisp_linedisp_lineDispLineDispLine, select_linesselect_linesselect_linesSelectLinesSelectLines, line_orientationline_orientationline_orientationLineOrientationLineOrientation

See also

regress_contours_xldregress_contours_xldregress_contours_xldRegressContoursXldRegressContoursXld, get_regress_params_xldget_regress_params_xldget_regress_params_xldGetRegressParamsXldGetRegressParamsXld

Module

Foundation


Table of Contents / XLD / Features ClassesClassesClasses | | | Operators
HALCON Reference Manual 10.0.2 Copyright © 1996-2011 MVTec Software GmbH