Skip to content

fit_circle_contour_xldfit_circle_contour_xldFitCircleContourXldFitCircleContourXldfit_circle_contour_xldfit_circle_contour_xldπŸ”—

Short descriptionπŸ”—

fit_circle_contour_xldfit_circle_contour_xldFitCircleContourXldFitCircleContourXldfit_circle_contour_xldfit_circle_contour_xld β€” Approximate XLD contours by circles.

SignatureπŸ”—

fit_circle_contour_xld( xld_cont Contours, string Algorithm, integer MaxNumPoints, real MaxClosureDist, integer ClippingEndPoints, integer Iterations, real ClippingFactor, out circle.center.y Row, out circle.center.x Column, out circle.radius Radius, out angle.rad StartPhi, out angle.rad EndPhi, out string PointOrder )fit_circle_contour_xld( Contours : : Algorithm, MaxNumPoints, MaxClosureDist, ClippingEndPoints, Iterations, ClippingFactor : Row, Column, Radius, StartPhi, EndPhi, PointOrder )void FitCircleContourXld( const HObject& Contours, const HTuple& Algorithm, const HTuple& MaxNumPoints, const HTuple& MaxClosureDist, const HTuple& ClippingEndPoints, const HTuple& Iterations, const HTuple& ClippingFactor, HTuple* Row, HTuple* Column, HTuple* Radius, HTuple* StartPhi, HTuple* EndPhi, HTuple* PointOrder )static void HOperatorSet.FitCircleContourXld( HObject contours, HTuple algorithm, HTuple maxNumPoints, HTuple maxClosureDist, HTuple clippingEndPoints, HTuple iterations, HTuple clippingFactor, out HTuple row, out HTuple column, out HTuple radius, out HTuple startPhi, out HTuple endPhi, out HTuple pointOrder )def fit_circle_contour_xld( contours: HObject, algorithm: str, max_num_points: int, max_closure_dist: float, clipping_end_points: int, iterations: int, clipping_factor: float ) -> Tuple[Sequence[float], Sequence[float], Sequence[float], Sequence[float], Sequence[float], Sequence[str]]

def fit_circle_contour_xld_s( contours: HObject, algorithm: str, max_num_points: int, max_closure_dist: float, clipping_end_points: int, iterations: int, clipping_factor: float ) -> Tuple[float, float, float, float, float, str]Herror fit_circle_contour_xld( const Hobject Contours, const char* Algorithm, const Hlong MaxNumPoints, double MaxClosureDist, const Hlong ClippingEndPoints, const Hlong Iterations, double ClippingFactor, double* Row, double* Column, double* Radius, double* StartPhi, double* EndPhi, char* PointOrder )

Herror T_fit_circle_contour_xld( const Hobject Contours, const Htuple Algorithm, const Htuple MaxNumPoints, const Htuple MaxClosureDist, const Htuple ClippingEndPoints, const Htuple Iterations, const Htuple ClippingFactor, Htuple* Row, Htuple* Column, Htuple* Radius, Htuple* StartPhi, Htuple* EndPhi, Htuple* PointOrder )

void HXLDCont::FitCircleContourXld( const HString& Algorithm, Hlong MaxNumPoints, double MaxClosureDist, Hlong ClippingEndPoints, Hlong Iterations, double ClippingFactor, HTuple* Row, HTuple* Column, HTuple* Radius, HTuple* StartPhi, HTuple* EndPhi, HTuple* PointOrder ) const

void HXLDCont::FitCircleContourXld( const HString& Algorithm, Hlong MaxNumPoints, double MaxClosureDist, Hlong ClippingEndPoints, Hlong Iterations, double ClippingFactor, double* Row, double* Column, double* Radius, double* StartPhi, double* EndPhi, HString* PointOrder ) const

void HXLDCont::FitCircleContourXld( const char* Algorithm, Hlong MaxNumPoints, double MaxClosureDist, Hlong ClippingEndPoints, Hlong Iterations, double ClippingFactor, double* Row, double* Column, double* Radius, double* StartPhi, double* EndPhi, HString* PointOrder ) const

void HXLDCont::FitCircleContourXld( const wchar_t* Algorithm, Hlong MaxNumPoints, double MaxClosureDist, Hlong ClippingEndPoints, Hlong Iterations, double ClippingFactor, double* Row, double* Column, double* Radius, double* StartPhi, double* EndPhi, HString* PointOrder ) const (Windows only)

void HXLDCont.FitCircleContourXld( string algorithm, int maxNumPoints, double maxClosureDist, int clippingEndPoints, int iterations, double clippingFactor, out HTuple row, out HTuple column, out HTuple radius, out HTuple startPhi, out HTuple endPhi, out HTuple pointOrder )

void HXLDCont.FitCircleContourXld( string algorithm, int maxNumPoints, double maxClosureDist, int clippingEndPoints, int iterations, double clippingFactor, out double row, out double column, out double radius, out double startPhi, out double endPhi, out string pointOrder )

DescriptionπŸ”—

fit_circle_contour_xldFitCircleContourXld approximates the XLD contours Contourscontourscontours by circles. 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 circle. The operator returns for each contour the center (Rowrowrow, Columncolumncolumn), and the Radiusradiusradius.

The algorithm used for the fitting of circles can be selected via Algorithmalgorithmalgorithm:

  • 'algebraic'"algebraic" This approach minimizes the algebraic distance between the contour points and the resulting circle.

  • 'ahuber'"ahuber" Similar to 'algebraic'"algebraic". Here the contour points are weighted to decrease the impact of outliers based on the approach of Huber (see below).

  • 'atukey'"atukey" Similar to 'algebraic'"algebraic". Here the contour points are weighted and outliers are ignored based on the approach of Tukey (see below).

  • 'geometric'"geometric" This approach minimizes the geometric distance between the contour points and the resulting circle. The distance measure is statistically optimal, but takes more computational time. This option is recommended if the contour points are considerably distorted by noise.

  • 'geohuber'"geohuber" Similar to 'geometric'"geometric". Here the contour points are weighted to decrease the impact of outliers based on the approach of Huber (see below).

  • 'geotukey'"geotukey" Similar to 'geometric'"geometric". Here the contour points are weighted and outliers are ignored based on the approach of Tukey (see below).

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 circle. The parameter ClippingFactorclippingFactorclipping_factor (a scaling factor for the standard deviation) controls the amount of outliers: the smaller the value chosen for ClippingFactorclippingFactorclipping_factor the more outliers are detected. In the Tukey algorithm outliers are removed, whereas in the Huber algorithm outliers are only damped, or more precisely they are weighted linearly. Without any robust weighting the squares of the distances are taken as error values in the optimization, i.e., a least square formulation. In practice, the approach of Tukey is recommended.

The parameter Iterationsiterationsiterations specifies the number of iterations for the algorithms 'algebraic'"algebraic", 'ahuber'"ahuber" and 'atukey'"atukey". This parameter is ignored for the algorithms 'geometric'"geometric", 'geohuber'"geohuber" and 'geotukey'"geotukey". If Iterationsiterationsiterations is set to zero, the algorithm does not perform iterative improvements on the fitted circle, but only checks if the initial guess was already close enough depending on the chosen treatment of outliers.

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

For circular arcs, the points on the circle closest to the start points and end points of the original contours are chosen as start and end points. The corresponding angles referring to the X-axis are returned in StartPhistartPhistart_phi and EndPhiendPhiend_phi, see also gen_ellipse_contour_xldGenEllipseContourXld. Contours, for which the distance between their start points and their end points is less or equal MaxClosureDistmaxClosureDistmax_closure_dist are considered to be closed. Thus, they are approximated by circles instead of circular arcs. Due to artifacts in the pre-processing the start and end points of a contour might be faulty. Therefore, it is possible to exclude ClippingEndPointsclippingEndPointsclipping_end_points points at the beginning and at the end of a contour from the fitting of circles. However, they are still used for the determination of StartPhistartPhistart_phi and EndPhiendPhiend_phi.

The minimum necessary number of contour points for fitting a circle is three. Therefore, it is required that the number of contour points is at least \(3 + 2 \cdot \textrm{ClippingEndPoints}\).

Execution informationπŸ”—

Execution information
  • Multithreading type: reentrant (runs in parallel with non-exclusive operators).

  • Multithreading scope: global (may be called from any thread).

  • Processed without parallelization.

ParametersπŸ”—

Contourscontourscontours (input_object) xld_cont(-array) β†’ objectobjectHObjectHXLDContHObjectHobject

Input contours.

Algorithmalgorithmalgorithm (input_control) string β†’ (string)(string)HTuple (HString)HTuple (string)strHtuple (char*)

Algorithm for the fitting of circles.

Default: 'algebraic'"algebraic"
List of values: 'ahuber', 'algebraic', 'atukey', 'geohuber', 'geometric', 'geotukey'"ahuber", "algebraic", "atukey", "geohuber", "geometric", "geotukey"

MaxNumPointsmaxNumPointsmax_num_points (input_control) integer β†’ (integer)(integer)HTuple (Hlong)HTuple (int / long)intHtuple (Hlong)

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

Default: -1-1
Restriction: MaxNumPoints >= 3

MaxClosureDistmaxClosureDistmax_closure_dist (input_control) real β†’ (real)(real)HTuple (double)HTuple (double)floatHtuple (double)

Maximum distance between the end points of a contour to be considered as β€˜closed’.

Default: 0.00.0
Restriction: MaxClosureDist >= 0.0

ClippingEndPointsclippingEndPointsclipping_end_points (input_control) integer β†’ (integer)(integer)HTuple (Hlong)HTuple (int / long)intHtuple (Hlong)

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

Default: 00
Restriction: ClippingEndPoints >= 0

Iterationsiterationsiterations (input_control) integer β†’ (integer)(integer)HTuple (Hlong)HTuple (int / long)intHtuple (Hlong)

Maximum number of iterations for the robust weighted fitting.

Default: 33
Restriction: Iterations >= 0

ClippingFactorclippingFactorclipping_factor (input_control) real β†’ (real)(real)HTuple (double)HTuple (double)floatHtuple (double)

Clipping factor for the elimination of outliers (typical: 1.0 for Huber and 2.0 for Tukey).

Default: 2.02.0
Suggested values: 1.0, 1.5, 2.0, 2.5, 3.01.0, 1.5, 2.0, 2.5, 3.0
Restriction: ClippingFactor > 0

Rowrowrow (output_control) circle.center.y(-array) β†’ (real)(real)HTuple (double)HTuple (double)Sequence[float]Htuple (double)

Row coordinate of the center of the circle.

Columncolumncolumn (output_control) circle.center.x(-array) β†’ (real)(real)HTuple (double)HTuple (double)Sequence[float]Htuple (double)

Column coordinate of the center of the circle.

Radiusradiusradius (output_control) circle.radius(-array) β†’ (real)(real)HTuple (double)HTuple (double)Sequence[float]Htuple (double)

Radius of circle.

StartPhistartPhistart_phi (output_control) angle.rad(-array) β†’ (real)(real)HTuple (double)HTuple (double)Sequence[float]Htuple (double)

Angle of the start point [rad].

EndPhiendPhiend_phi (output_control) angle.rad(-array) β†’ (real)(real)HTuple (double)HTuple (double)Sequence[float]Htuple (double)

Angle of the end point [rad].

PointOrderpointOrderpoint_order (output_control) string(-array) β†’ (string)(string)HTuple (HString)HTuple (string)Sequence[str]Htuple (char*)

Point order along the boundary.

List of values: 'negative', 'positive'"negative", "positive"

ResultπŸ”—

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

Combinations with other operatorsπŸ”—

Combinations

Possible predecessors

gen_contours_skeleton_xldGenContoursSkeletonXld, lines_gaussLinesGauss, lines_facetLinesFacet, edges_sub_pixEdgesSubPix, smooth_contours_xldSmoothContoursXld

Possible successors

gen_ellipse_contour_xldGenEllipseContourXld, disp_circleDispCircle, get_points_ellipseGetPointsEllipse

See also

fit_ellipse_contour_xldFitEllipseContourXld, fit_line_contour_xldFitLineContourXld, fit_rectangle2_contour_xldFitRectangle2ContourXld

ModuleπŸ”—

Foundation