Herror ::fit_ellipse_contour_xld (
Hobject Contours,
const HTuple &Algorithm,
const HTuple &MaxNumPoints,
const HTuple &MaxClosureDist,
const HTuple &ClippingEndPoints,
const HTuple &VossTabSize,
const HTuple &Iterations,
const HTuple &ClippingFactor,
double *Row,
double *Column,
double *Phi,
double *Radius1,
double *Radius2,
double *StartPhi,
double *EndPhi,
char *PointOrder
)
Herror ::fit_ellipse_contour_xld (
Hobject Contours,
const HTuple &Algorithm,
const HTuple &MaxNumPoints,
const HTuple &MaxClosureDist,
const HTuple &ClippingEndPoints,
const HTuple &VossTabSize,
const HTuple &Iterations,
const HTuple &ClippingFactor,
HTuple *Row,
HTuple *Column,
HTuple *Phi,
HTuple *Radius1,
HTuple *Radius2,
HTuple *StartPhi,
HTuple *EndPhi,
HTuple *PointOrder
)
double HXLDCont::FitEllipseContourXld (
const HTuple &Algorithm,
const HTuple &MaxNumPoints,
const HTuple &MaxClosureDist,
const HTuple &ClippingEndPoints,
const HTuple &VossTabSize,
const HTuple &Iterations,
const HTuple &ClippingFactor,
double *Column,
double *Phi,
double *Radius1,
double *Radius2,
double *StartPhi,
double *EndPhi,
char *PointOrder
) const
HTuple HXLDContArray::FitEllipseContourXld (
const HTuple &Algorithm,
const HTuple &MaxNumPoints,
const HTuple &MaxClosureDist,
const HTuple &ClippingEndPoints,
const HTuple &VossTabSize,
const HTuple &Iterations,
const HTuple &ClippingFactor,
HTuple *Column,
HTuple *Phi,
HTuple *Radius1,
HTuple *Radius2,
HTuple *StartPhi,
HTuple *EndPhi,
HTuple *PointOrder
) const
Approximation of XLD contours by ellipses or elliptic arcs.
::fit_ellipse_contour_xld approximates the XLD contours
Contours by elliptic arcs or closed ellipses. 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 elliptic structure.
The operator returns for each contour the center
(Row, Column), the orientation of the main
axis Phi, the length of the larger half axis Radius1,
and the length of the smaller half axis Radius2 of the underlying
ellipse. In addition to that, the angle corresponding to the start point
and the end point StartPhi, EndPhi,
and the point order along the boundary PointOrder
is returned for elliptic arcs. These parameters are set to
0, 2*PI, and 'positive' for closed ellipses.
The algorithm used for the fitting of ellipses can be selected via
Algorithm:
'fitzgibbon':
This approach minimizes the algebraic distance
a*Xi^2 + b*Xi*Yi + c*Yi^2 + d*Xi + e*Yi + f
between the contour points (Xi,Yi) and the resulting ellipse. The
constraint 4ac - b^2 = 1 guarantees that the resulting polynom
characterizes an ellipse (instead of a hyperbola or a parabola).
'fhuber':
Similar to 'fitzgibbon'. Here the contour points are weighted
to decrease the impact of outliers based on
the approach of Huber.
'ftukey':
Similar to 'fitzgibbon'. Here the contour points are weighted
to decrease the impact of outliers based on
the approach of Tukey.
'voss':
Each input contour is transformed in an affine standard position.
Based on the moments of the transformed contour (that is of the
enclosed image region) the standard circular segment is choosen
whose standard position matches best with the standard position
of the contour. The ellipse corresponding to the standard
position of the selected circular segment is re-transformed
based on the affine transformation which produced the standard position
of the contour resulting in the ellipse matching the original contour.
VossTabSize standard circular segments are used for
this computation. To speed up the process the corresponding moments
and other data is stored in a table which is created during the
first call (with a specific value for VossTabSize) to
::fit_ellipse_contour_xld.
'focpoints':
Each point P on an ellipse satisfies the constraint that the sum
of distances to the focal points F1,F2 equals twice the
length of the larger half axis a. In this approach, the deviation
PF1 + PF2 - 2a is minimized for all contour points by a
least squares optimization.
'fphuber':
Similar to 'focpoints'. Here a weighted least squares
optimization is done to decrease the impact of outliers based on
the approach of Huber.
'fptukey':
Similar to 'focpoints'. Here a weighted least squares
optimization is done to decrease the impact of outliers based on
the approach of Tukey.
For '*Huber' and '*Tukey' a robust error statistics is used to
estimate the standard deviation of the distances from the contour
points {without} outliers from the approximating ellipse.
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 and the least squares fitting in the
mode 'focpoints' is repeated. The parameter
Iterations specifies the number of iterations.
To reduce the computational load, the fitting of ellipses 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.
For elliptic arcs, the points on the ellipse closest to the
start points and end points of the original contours are chosen
as start and end points. The corresponding angles refering to the
main axis of the ellipse are returned in StartPhi and
EndPhi, see also ::gen_ellipse_contour_xld.
Contours, for which the distance between their start points and
their end points is less or equal MaxClosureDist
are considered to be closed. Thus, they are approximated by
ellipses instead of elliptic arcs.
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 fitting of ellipses. However, they are still
used for the determination of StartPhi and
EndPhi.
Parameters
Contours (input_object)
|
xld_cont(-array) -> Hobject: HXLDCont(Array)
|
|
Input contours. |
Algorithm (input_control)
|
string -> HTuple.char *
|
|
Algorithm for the fitting of ellipses. |
|
Default value: 'fitzgibbon' |
|
List of values: 'fitzgibbon', 'fhuber', 'ftukey', 'voss', 'focpoints', 'fphuber', 'fptukey' |
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 |
MaxClosureDist (input_control)
|
real -> HTuple.double
|
|
Maximum distance between the end points of a
contour to be considered as 'closed'. |
|
Default value: 2.0 |
|
Restriction: MaxClosureDist >= 0.0 |
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 |
VossTabSize (input_control)
|
integer -> HTuple.long
|
|
Number of circular segments used for the Voss approach. |
|
Default value: 200 |
|
Restriction: (VossTabSize >= 25) && (VossTabSize <= 5000) |
Iterations (input_control)
|
integer -> HTuple.long
|
|
Maximum number of iterations (unused for
'fitzgibbon' and 'voss'). |
|
Default value: 3 |
|
Restriction: Iterations >= 0 |
ClippingFactor (input_control)
|
real -> HTuple.double
|
|
Clipping factor for the elimination of outliers
(typical: 1.0 for '*Huber' 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 |
Row (output_control)
|
ellipse.center.y(-array) -> (HTuple.) double *
|
|
Row coordinate of the center of the ellipse. |
Column (output_control)
|
ellipse.center.x(-array) -> (HTuple.) double *
|
|
Column coordinate of the center of the ellipse. |
Phi (output_control)
|
ellipse.angle.rad(-array) -> (HTuple.) double *
|
|
Orientation of the main axis [rad]. |
Radius1 (output_control)
|
ellipse.radius1(-array) -> (HTuple.) double *
|
|
Length of the larger half axis. |
Radius2 (output_control)
|
ellipse.radius2(-array) -> (HTuple.) double *
|
|
Length of the smaller half axis. |
StartPhi (output_control)
|
real(-array) -> (HTuple.) double *
|
|
Angle of the start point [rad]. |
EndPhi (output_control)
|
real(-array) -> (HTuple.) double *
|
|
Angle of the end point [rad]. |
PointOrder (output_control)
|
string(-array) -> (HTuple.) char *
|
|
point order along the boundary. |
|
List of values: 'positive', 'negative' |
Example
read_image (Image, "caltab");
find_caltab (Image, &Caltab, "caltabBig.descr", 3, 112, 5)
reduce_domain (Image, Caltab, &ImageReduced);
edges_sub_pix (ImageReduced, &Edges, "lanser2", 0.5, 20, 40);
select_contours_xld (Edges, &EdgesClosed, "closed", 0, 2.0, 0, 0);
select_contours_xld (EdgesClosed, &EdgesMarks, "length", 20, 80, 0, 0);
fit_ellipse_contour_xld (EdgesMarks, "fitzgibbon", -1, 2, 0, 200, 3, 2.0,
&Row, &Column, &Phi, &Radius1, &Radius2, &StartPhi,
&EndPhi, &PointOrder);
gen_ellipse_contour_xld (&EllMarks, Row, Column, Phi, Radius1, Radius2,
StartPhi, EndPhi, PointOrder, 1.5);
length_xld(EllMarks,&Length);
Result
::fit_ellipse_contour_xld returns H_MSG_TRUE if all parameter values
are correct, and ellipses 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
::gen_ellipse_contour_xld,
::disp_ellipse,
::get_points_ellipse
See also
::fit_line_contour_xld
Module
Sub-pixel operators
Copyright © 1996-2002 MVTec Software GmbH