segment_contours_xldsegment_contours_xldSegmentContoursXldSegmentContoursXldsegment_contours_xld (Operator)

Name

segment_contours_xldsegment_contours_xldSegmentContoursXldSegmentContoursXldsegment_contours_xld — Segment XLD contours into line segments and circular or elliptic arcs.

Signature

segment_contours_xld(Contours : ContoursSplit : Mode, SmoothCont, MaxLineDist1, MaxLineDist2 : )

Herror segment_contours_xld(const Hobject Contours, Hobject* ContoursSplit, const char* Mode, const Hlong SmoothCont, double MaxLineDist1, double MaxLineDist2)

Herror T_segment_contours_xld(const Hobject Contours, Hobject* ContoursSplit, const Htuple Mode, const Htuple SmoothCont, const Htuple MaxLineDist1, const Htuple MaxLineDist2)

void SegmentContoursXld(const HObject& Contours, HObject* ContoursSplit, const HTuple& Mode, const HTuple& SmoothCont, const HTuple& MaxLineDist1, const HTuple& MaxLineDist2)

HXLDCont HXLDCont::SegmentContoursXld(const HString& Mode, Hlong SmoothCont, double MaxLineDist1, double MaxLineDist2) const

HXLDCont HXLDCont::SegmentContoursXld(const char* Mode, Hlong SmoothCont, double MaxLineDist1, double MaxLineDist2) const

HXLDCont HXLDCont::SegmentContoursXld(const wchar_t* Mode, Hlong SmoothCont, double MaxLineDist1, double MaxLineDist2) const   ( Windows only)

static void HOperatorSet.SegmentContoursXld(HObject contours, out HObject contoursSplit, HTuple mode, HTuple smoothCont, HTuple maxLineDist1, HTuple maxLineDist2)

HXLDCont HXLDCont.SegmentContoursXld(string mode, int smoothCont, double maxLineDist1, double maxLineDist2)

def segment_contours_xld(contours: HObject, mode: str, smooth_cont: int, max_line_dist_1: float, max_line_dist_2: float) -> HObject

Description

segment_contours_xldsegment_contours_xldSegmentContoursXldSegmentContoursXldSegmentContoursXldsegment_contours_xld segments the input contours ContoursContoursContoursContourscontourscontours into lines if ModeModeModeModemodemode='lines'"lines""lines""lines""lines""lines", into lines and circular arcs if ModeModeModeModemodemode='lines_circles'"lines_circles""lines_circles""lines_circles""lines_circles""lines_circles", or into lines and elliptic arcs if ModeModeModeModemodemode='lines_ellipses'"lines_ellipses""lines_ellipses""lines_ellipses""lines_ellipses""lines_ellipses". The segmented contours are returned in ContoursSplitContoursSplitContoursSplitContoursSplitcontoursSplitcontours_split. The information on whether an output contour represents a line or a circular or elliptic arc is done via the global contour attribute 'cont_approx'"cont_approx""cont_approx""cont_approx""cont_approx""cont_approx" (see get_contour_global_attrib_xldget_contour_global_attrib_xldGetContourGlobalAttribXldGetContourGlobalAttribXldGetContourGlobalAttribXldget_contour_global_attrib_xld for further information).

segment_contours_xldsegment_contours_xldSegmentContoursXldSegmentContoursXldSegmentContoursXldsegment_contours_xld first approximates the input contours by polygons. With this, the contours are oversegmented in curved areas. After this, the contours are approximated according to the modes ModeModeModeModemodemode given below. If SmoothContSmoothContSmoothContSmoothContsmoothContsmooth_cont is set to a value > 0, the input contours are first smoothed (see smooth_contours_xldsmooth_contours_xldSmoothContoursXldSmoothContoursXldSmoothContoursXldsmooth_contours_xld). This can be necessary to prevent very short segments in the polygonal approximation and to achieve a more robust fit with circular or elliptic arcs, because the smoothing suppresses outliers on the contours.

The calculation of the segmentation depends on the respective selected method in ModeModeModeModemodemode:

'lines'"lines""lines""lines""lines""lines"

The Ramer algorithm is used to perform a polygon approximation with a maximum distance of MaxLineDist1MaxLineDist1MaxLineDist1MaxLineDist1maxLineDist1max_line_dist_1 (see gen_polygons_xldgen_polygons_xldGenPolygonsXldGenPolygonsXldGenPolygonsXldgen_polygons_xld). If ModeModeModeModemodemode='lines'"lines""lines""lines""lines""lines", the parameter MaxLineDist2MaxLineDist2MaxLineDist2MaxLineDist2maxLineDist2max_line_dist_2 is ignored.

'lines_circles'"lines_circles""lines_circles""lines_circles""lines_circles""lines_circles" or 'lines_ellipses'"lines_ellipses""lines_ellipses""lines_ellipses""lines_ellipses""lines_ellipses"

The initial polygonal approximation is done by using the Ramer algorithm (see gen_polygons_xldgen_polygons_xldGenPolygonsXldGenPolygonsXldGenPolygonsXldgen_polygons_xld) with a maximum distance of MaxLineDist1MaxLineDist1MaxLineDist1MaxLineDist1maxLineDist1max_line_dist_1. If the maximum distance of the resulting arc to the contour is smaller than the maximum distance of the two line segments, the two line segments are replaced with the arc. This procedure is iterated until no more changes occur. After this, the parts of the contour that are still approximated by line segments are again segmented with a polygonal approximation with maximum distance MaxLineDist2MaxLineDist2MaxLineDist2MaxLineDist2maxLineDist2max_line_dist_2, and the newly created line segments are merged to circular or elliptical arcs where possible. This changes the output only if MaxLineDist2MaxLineDist2MaxLineDist2MaxLineDist2maxLineDist2max_line_dist_2 differs from MaxLineDist1MaxLineDist1MaxLineDist1MaxLineDist1maxLineDist1max_line_dist_1. This two-step approach is more efficient than a one-step approach with MaxLineDist2MaxLineDist2MaxLineDist2MaxLineDist2maxLineDist2max_line_dist_2, since fewer line segments are generated in the first step, and hence the circle or ellipse fit has to be performed less often. Therefore, parts of the input contours that can be approximated by long arcs can be found more efficiently. In the second step, parts of the input contours that can be approximated by short arcs are found and the end parts of long arcs are refined. In order to benefit from this two-step approach it is recommended to set MaxLineDist2MaxLineDist2MaxLineDist2MaxLineDist2maxLineDist2max_line_dist_2 < MaxLineDist1MaxLineDist1MaxLineDist1MaxLineDist1maxLineDist1max_line_dist_1.

The resulting contours are at least 3 pixel long and contain at least 6 successive points of the input contour. All input contours with a length less than 3 pixel or with less than 6 contour points are copied to the output contours without modifications.

Execution Information

Parameters

ContoursContoursContoursContourscontourscontours (input_object)  xld_cont(-array) objectHXLDContHObjectHXLDContHobject

Contours to be segmented.

ContoursSplitContoursSplitContoursSplitContoursSplitcontoursSplitcontours_split (output_object)  xld_cont-array objectHXLDContHObjectHXLDContHobject *

Segmented contours.

ModeModeModeModemodemode (input_control)  string HTuplestrHTupleHtuple (string) (string) (HString) (char*)

Mode for the segmentation of the contours.

Default: 'lines_circles' "lines_circles" "lines_circles" "lines_circles" "lines_circles" "lines_circles"

List of values: 'lines'"lines""lines""lines""lines""lines", 'lines_circles'"lines_circles""lines_circles""lines_circles""lines_circles""lines_circles", 'lines_ellipses'"lines_ellipses""lines_ellipses""lines_ellipses""lines_ellipses""lines_ellipses"

SmoothContSmoothContSmoothContSmoothContsmoothContsmooth_cont (input_control)  integer HTupleintHTupleHtuple (integer) (int / long) (Hlong) (Hlong)

Number of points used for smoothing the contours.

Default: 5

Suggested values: 0, 3, 5, 7, 9

Restriction: SmoothCont == 0 || SmoothCont >= 3 && odd(SmoothCont)

MaxLineDist1MaxLineDist1MaxLineDist1MaxLineDist1maxLineDist1max_line_dist_1 (input_control)  real HTuplefloatHTupleHtuple (real) (double) (double) (double)

Maximum distance between a contour and the approximating line (first iteration).

Default: 4.0

Suggested values: 1.0, 1.5, 2.0, 2.5, 3.0, 3.5

Restriction: MaxLineDist1 >= 0.0

MaxLineDist2MaxLineDist2MaxLineDist2MaxLineDist2maxLineDist2max_line_dist_2 (input_control)  real HTuplefloatHTupleHtuple (real) (double) (double) (double)

Maximum distance between a contour and the approximating line (second iteration).

Default: 2.0

Suggested values: 1.0, 1.5, 2.0, 2.5, 3.0, 3.5

Restriction: MaxLineDist2 >= 0.0

Example (HDevelop)

read_image (Image, 'pumpe')
edges_sub_pix (Image, Edges, 'canny', 1.5, 15, 40)
segment_contours_xld (Edges, ContoursSplit, 'lines_circles', 5, 4, 2)
count_obj (ContoursSplit, Number)
gen_empty_obj (Lines)
gen_empty_obj (Circles)
for I := 1 to Number by 1
  select_obj (ContoursSplit, Contour, I)
  get_contour_global_attrib_xld (Contour, 'cont_approx', Type)
  if (Type == -1)
      concat_obj (Lines, Contour, Lines)
  else
      concat_obj (Circles, Contour, Circles)
  endif
endfor
fit_line_contour_xld (Lines, 'tukey', -1, 0, 5, 2, RowBegin, ColBegin, \
                      RowEnd, ColEnd, Nr, Nc, Dist)
fit_circle_contour_xld (Circles, 'atukey', -1, 2, 0, 3, 2, Row, Column, \
                        Radius, StartPhi, EndPhi, PointOrder)

Possible Predecessors

gen_contours_skeleton_xldgen_contours_skeleton_xldGenContoursSkeletonXldGenContoursSkeletonXldGenContoursSkeletonXldgen_contours_skeleton_xld, lines_gausslines_gaussLinesGaussLinesGaussLinesGausslines_gauss, edges_sub_pixedges_sub_pixEdgesSubPixEdgesSubPixEdgesSubPixedges_sub_pix

Possible Successors

fit_line_contour_xldfit_line_contour_xldFitLineContourXldFitLineContourXldFitLineContourXldfit_line_contour_xld, fit_ellipse_contour_xldfit_ellipse_contour_xldFitEllipseContourXldFitEllipseContourXldFitEllipseContourXldfit_ellipse_contour_xld, fit_circle_contour_xldfit_circle_contour_xldFitCircleContourXldFitCircleContourXldFitCircleContourXldfit_circle_contour_xld, get_contour_global_attrib_xldget_contour_global_attrib_xldGetContourGlobalAttribXldGetContourGlobalAttribXldGetContourGlobalAttribXldget_contour_global_attrib_xld

See also

split_contours_xldsplit_contours_xldSplitContoursXldSplitContoursXldSplitContoursXldsplit_contours_xld, get_contour_global_attrib_xldget_contour_global_attrib_xldGetContourGlobalAttribXldGetContourGlobalAttribXldGetContourGlobalAttribXldget_contour_global_attrib_xld, smooth_contours_xldsmooth_contours_xldSmoothContoursXldSmoothContoursXldSmoothContoursXldsmooth_contours_xld, gen_polygons_xldgen_polygons_xldGenPolygonsXldGenPolygonsXldGenPolygonsXldgen_polygons_xld

Module

Foundation