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
)
long 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

Approximation of XLD contours by line segments.

::fit_line_contour_xld approximates the XLD contours Contours 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 (RowBegin, ColBegin), the end point (RowEnd, ColEnd), and the regression line to the contour given by the normal vector (Nr, Nc) of the line and its distance Dist from the origin, i.e., the line equation is given by r *Nr + c * Nc -d = 0.

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

'regression':
Standard 'least squares' line fitting.

'huber':
Weighted 'least squares' line fitting, where the impact of outliers
is decreased based on the approach of Huber.

'tukey':
Weighted 'least squares' line fitting, where the impact of outliers
is decreased based on the approach of Tukey.

'drop':
Weighted 'least squares' line fitting, where outliers are
eliminated.

'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 {\em without\/} outliers from the approximating line. The parameter ClippingFactor (a scaling factor for the standard deviation) controls the amount of damping outliers: The smaller the value chosen for ClippingFactor the more outliers are detected. The detection of outliers is repeated. The parameter Iterations specifies the number of iterations. In the modus 'regression' this value is ignored.

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 MaxNumPoints, only up to MaxNumPoints 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 ClippingEndPoints 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.


Parameters

Contours (input_object)
xld_cont(-array) -> Hobject: HXLDCont(Array)
Input contours.

Algorithm (input_control)
string -> HTuple.char *
Algorithm for the fitting of lines.
Default value: 'tukey'
List of values: 'regression', 'huber', 'tukey', 'gauss', 'drop'

MaxNumPoints (input_control)
integer -> HTuple.long
Maximum number of contour points used for the computation (-1 for all points).
Default value: -1
Restriction: MaxNumPoints >= 3

ClippingEndPoints (input_control)
integer -> HTuple.long
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

Iterations (input_control)
integer -> HTuple.long
Maximum number of iterations (unused for 'regression').
Default value: 5
Restriction: Iterations >= 0

ClippingFactor (input_control)
real -> HTuple.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

RowBegin (output_control)
line.begin.y(-array) -> (HTuple.) double *
Row coordinates of the starting points of the line segments.

ColBegin (output_control)
line.begin.x(-array) -> (HTuple.) double *
Column coordinates of the starting points of the line segments.

RowEnd (output_control)
line.end.y(-array) -> (HTuple.) double *
Row coordinates of the end points of the line segments.

ColEnd (output_control)
line.end.x(-array) -> (HTuple.) double *
Column coordinates of the end points of the line segments.

Nr (output_control)
number(-array) -> (HTuple.) double *
Line parameter: Row coordinate of the normal vector

Nc (output_control)
number(-array) -> (HTuple.) double *
Line parameter: Column coordinate of the normal vector

Dist (output_control)
number(-array) -> (HTuple.) double *
Line parameter: Distance of the line from the origin


Example
draw_ellipse(WindowHandle,Row,Column,Phi,Radius1,Radius2);
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);

Result

::fit_line_contour_xld returns 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>). If necessary, an exception is raised.


Possible Predecessors

::gen_contours_skeleton_xld, ::lines_gauss, ::lines_facet, ::edges_sub_pix, ::smooth_contours_xld


Possible Successors

::disp_line, ::select_lines, ::line_orientation


See also

::regress_contours_xld, ::get_regress_params_xld


Module

Sub-pixel operators



Copyright © 1996-2002 MVTec Software GmbH