Skip to content

segment_contours_xldSegmentContoursXldSegmentContoursXldsegment_contours_xldsegment_contours_xld🔗

Short description🔗

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

Signature🔗

segment_contours_xld( xld_cont Contours, out xld_cont ContoursSplit, string Mode, integer SmoothCont, real MaxLineDist1, real MaxLineDist2 )void SegmentContoursXld( const HObject& Contours, HObject* ContoursSplit, const HTuple& Mode, const HTuple& SmoothCont, const HTuple& MaxLineDist1, const HTuple& MaxLineDist2 )static void HOperatorSet.SegmentContoursXld( HObject contours, out HObject contoursSplit, HTuple mode, HTuple smoothCont, HTuple maxLineDist1, HTuple maxLineDist2 )def segment_contours_xld( contours: HObject, mode: str, smooth_cont: int, max_line_dist_1: float, max_line_dist_2: float ) -> HObject

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 )

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)

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

Description🔗

segment_contours_xldSegmentContoursXld segments the input contours Contourscontourscontours into lines if Modemodemode='lines'"lines", into lines and circular arcs if Modemodemode='lines_circles'"lines_circles", or into lines and elliptic arcs if Modemodemode='lines_ellipses'"lines_ellipses". The segmented contours are returned in ContoursSplitcontoursSplitcontours_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" (see get_contour_global_attrib_xldGetContourGlobalAttribXld for further information).

segment_contours_xldSegmentContoursXld 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 Modemodemode given below. If SmoothContsmoothContsmooth_cont is set to a value \(> 0\), the input contours are first smoothed (see smooth_contours_xldSmoothContoursXld). 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 Modemodemode:

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🔗

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) → objectHObjectHXLDContHObjectHobject

Contours to be segmented.

ContoursSplitcontoursSplitcontours_split (output_object) xld_cont-array → objectHObjectHXLDContHObjectHobject *

Segmented contours.

Modemodemode (input_control) string → (string)HTuple (HString)HTuple (string)strHtuple (char*)

Mode for the segmentation of the contours.

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

SmoothContsmoothContsmooth_cont (input_control) integer → (integer)HTuple (Hlong)HTuple (int / long)intHtuple (Hlong)

Number of points used for smoothing the contours.

Default: 55
Suggested values: 0, 3, 5, 7, 90, 3, 5, 7, 9
Restriction: SmoothCont == 0 || (SmoothCont >= 3 && odd(SmoothCont))

MaxLineDist1maxLineDist1max_line_dist_1 (input_control) real → (real)HTuple (double)HTuple (double)floatHtuple (double)

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

Default: 4.04.0
Suggested values: 1.0, 1.5, 2.0, 2.5, 3.0, 3.51.0, 1.5, 2.0, 2.5, 3.0, 3.5
Restriction: MaxLineDist1 >= 0.0

MaxLineDist2maxLineDist2max_line_dist_2 (input_control) real → (real)HTuple (double)HTuple (double)floatHtuple (double)

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

Default: 2.02.0
Suggested values: 1.0, 1.5, 2.0, 2.5, 3.0, 3.51.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)

Combinations with other operators🔗

Combinations

Possible predecessors

gen_contours_skeleton_xldGenContoursSkeletonXld, lines_gaussLinesGauss, edges_sub_pixEdgesSubPix

Possible successors

fit_line_contour_xldFitLineContourXld, fit_ellipse_contour_xldFitEllipseContourXld, fit_circle_contour_xldFitCircleContourXld, get_contour_global_attrib_xldGetContourGlobalAttribXld

See also

split_contours_xldSplitContoursXld, get_contour_global_attrib_xldGetContourGlobalAttribXld, smooth_contours_xldSmoothContoursXld, gen_polygons_xldGenPolygonsXld

Module🔗

Foundation