Skip to content

approx_chainApproxChainApproxChainapprox_chainT_approx_chainπŸ”—

Short descriptionπŸ”—

approx_chainApproxChainApproxChainapprox_chainT_approx_chain β€” Approximate a contour by arcs and lines.

WarningπŸ”—

approx_chainApproxChain is obsolete and is only provided for reasons of backward compatibility.

SignatureπŸ”—

approx_chain( point.y Row, point.x Column, real MinWidthCoord, real MaxWidthCoord, real ThreshStart, real ThreshEnd, real ThreshStep, real MinWidthSmooth, real MaxWidthSmooth, integer MinWidthCurve, integer MaxWidthCurve, real Weight1, real Weight2, real Weight3, out arc.center.y ArcCenterRow, out arc.center.x ArcCenterCol, out arc.angle.rad ArcAngle, out arc.begin.y ArcBeginRow, out arc.begin.x ArcBeginCol, out line.begin.y LineBeginRow, out line.begin.x LineBeginCol, out line.end.y LineEndRow, out line.end.x LineEndCol, out integer Order )void ApproxChain( const HTuple& Row, const HTuple& Column, const HTuple& MinWidthCoord, const HTuple& MaxWidthCoord, const HTuple& ThreshStart, const HTuple& ThreshEnd, const HTuple& ThreshStep, const HTuple& MinWidthSmooth, const HTuple& MaxWidthSmooth, const HTuple& MinWidthCurve, const HTuple& MaxWidthCurve, const HTuple& Weight1, const HTuple& Weight2, const HTuple& Weight3, HTuple* ArcCenterRow, HTuple* ArcCenterCol, HTuple* ArcAngle, HTuple* ArcBeginRow, HTuple* ArcBeginCol, HTuple* LineBeginRow, HTuple* LineBeginCol, HTuple* LineEndRow, HTuple* LineEndCol, HTuple* Order )static void HOperatorSet.ApproxChain( HTuple row, HTuple column, HTuple minWidthCoord, HTuple maxWidthCoord, HTuple threshStart, HTuple threshEnd, HTuple threshStep, HTuple minWidthSmooth, HTuple maxWidthSmooth, HTuple minWidthCurve, HTuple maxWidthCurve, HTuple weight1, HTuple weight2, HTuple weight3, out HTuple arcCenterRow, out HTuple arcCenterCol, out HTuple arcAngle, out HTuple arcBeginRow, out HTuple arcBeginCol, out HTuple lineBeginRow, out HTuple lineBeginCol, out HTuple lineEndRow, out HTuple lineEndCol, out HTuple order )def approx_chain( row: Sequence[int], column: Sequence[int], min_width_coord: float, max_width_coord: float, thresh_start: float, thresh_end: float, thresh_step: float, min_width_smooth: float, max_width_smooth: float, min_width_curve: int, max_width_curve: int, weight_1: float, weight_2: float, weight_3: float ) -> Tuple[Sequence[int], Sequence[int], Sequence[float], Sequence[int], Sequence[int], Sequence[int], Sequence[int], Sequence[int], Sequence[int], Sequence[int]]

Herror T_approx_chain( const Htuple Row, const Htuple Column, const Htuple MinWidthCoord, const Htuple MaxWidthCoord, const Htuple ThreshStart, const Htuple ThreshEnd, const Htuple ThreshStep, const Htuple MinWidthSmooth, const Htuple MaxWidthSmooth, const Htuple MinWidthCurve, const Htuple MaxWidthCurve, const Htuple Weight1, const Htuple Weight2, const Htuple Weight3, Htuple* ArcCenterRow, Htuple* ArcCenterCol, Htuple* ArcAngle, Htuple* ArcBeginRow, Htuple* ArcBeginCol, Htuple* LineBeginRow, Htuple* LineBeginCol, Htuple* LineEndRow, Htuple* LineEndCol, Htuple* Order )

static void HMisc::ApproxChain( const HTuple& Row, const HTuple& Column, double MinWidthCoord, double MaxWidthCoord, double ThreshStart, double ThreshEnd, double ThreshStep, double MinWidthSmooth, double MaxWidthSmooth, Hlong MinWidthCurve, Hlong MaxWidthCurve, double Weight1, double Weight2, double Weight3, HTuple* ArcCenterRow, HTuple* ArcCenterCol, HTuple* ArcAngle, HTuple* ArcBeginRow, HTuple* ArcBeginCol, HTuple* LineBeginRow, HTuple* LineBeginCol, HTuple* LineEndRow, HTuple* LineEndCol, HTuple* Order )

static void HMisc.ApproxChain( HTuple row, HTuple column, double minWidthCoord, double maxWidthCoord, double threshStart, double threshEnd, double threshStep, double minWidthSmooth, double maxWidthSmooth, int minWidthCurve, int maxWidthCurve, double weight1, double weight2, double weight3, out HTuple arcCenterRow, out HTuple arcCenterCol, out HTuple arcAngle, out HTuple arcBeginRow, out HTuple arcBeginCol, out HTuple lineBeginRow, out HTuple lineBeginCol, out HTuple lineEndRow, out HTuple lineEndCol, out HTuple order )

DescriptionπŸ”—

The coordinates of a curve are approximated by a row of lines and arcs. The procedure tries values from a user-definable range for certain parameters. The limits of these ranges are explicitly stated in the parameter list of the function (MinWidthCoord … MaxWidthCoord, ThreshStart … ThreshEnd, MinWidthSmooth … MaxWidthSmooth, MinWidthCurve … MaxWidthCurve). Additionally, the step width for the parameter area of the threshold value for pointed corners has to be indicated (ThreshStep). By narrowing the covered areas the runtime of the calculation can be shortened, but the result may deteriorate.

The parameters Weight1, Weight2 and Weight3 indicate whether the desired weighting is placed more on precision of the approximation, obtaining as much large segments as possible or as few small segments as possible. Thus, for (Weight1,Weight2,Weight3) (1,0,0) creates a very precise approximation and (0,1,1) an approximation with as few large segments as possible.

The result of the procedure is returned separately as arcs and lines. If one is interested in the sequence of the segments the individual resulting elements can be read successively from the resulting tuples; the sequence can be taken from the return parameter order (0: next element is next line segment, 1: next element is next arc segment).

AttentionπŸ”—

Contours which can possibly consist of only one segment should also be examined with a threshold maximum (ThreshEnd) \(>\) 1.0, because otherwise at least one β€œcorner point” is determined in any case.

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πŸ”—

Rowrowrow (input_control) point.y-array β†’ (integer)HTuple (Hlong)HTuple (int / long)Sequence[int]Htuple (Hlong)

Row of the contour.

Default: 3232

Columncolumncolumn (input_control) point.x-array β†’ (integer)HTuple (Hlong)HTuple (int / long)Sequence[int]Htuple (Hlong)

Column of the contour.

Default: 3232

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

Minimum width of Gauss operator for coordinate smoothing (\(>\) 0.4).

Default: 0.50.5
Suggested values: 0.5, 0.7, 1.0, 1.2, 1.5, 1.70.5, 0.7, 1.0, 1.2, 1.5, 1.7
Value range: 0.4 ≀ MinWidthCoord ≀ 3.0 (lin)
Minimum increment: 0.01
Recommended increment: 0.1

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

Maximum width of Gauss operator for coordinate smoothing (\(>\) 0.4).

Default: 2.42.4
Suggested values: 0.5, 0.7, 1.0, 1.2, 1.5, 1.70.5, 0.7, 1.0, 1.2, 1.5, 1.7
Value range: 0.4 ≀ MaxWidthCoord ≀ 3.0 (lin)
Minimum increment: 0.01
Recommended increment: 0.1

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

Minimum threshold value of the curvature for accepting a corner (relative to the largest curvature present).

Default: 0.30.3
Suggested values: 0.3, 0.4, 0.5, 0.6, 0.7, 0.80.3, 0.4, 0.5, 0.6, 0.7, 0.8
Value range: 0.1 ≀ ThreshStart ≀ 0.9 (lin)
Minimum increment: 0.01
Recommended increment: 0.1

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

Maximum threshold value of the curvature for accepting a corner (relative to the largest curvature present).

Default: 0.90.9
Suggested values: 0.3, 0.4, 0.5, 0.6, 0.7, 0.80.3, 0.4, 0.5, 0.6, 0.7, 0.8
Value range: 0.1 ≀ ThreshEnd ≀ 0.9 (lin)
Minimum increment: 0.01
Recommended increment: 0.1

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

Step width for threshold increase.

Default: 0.20.2
Suggested values: 0.3, 0.4, 0.50.3, 0.4, 0.5
Value range: 0.1 ≀ ThreshStep ≀ 0.9 (lin)
Minimum increment: 0.01
Recommended increment: 0.1

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

Minimum width of Gauss operator for smoothing the curvature function (\(>\) 0.4).

Default: 0.50.5
Suggested values: 0.5, 0.7, 1.0, 1.2, 1.5, 1.70.5, 0.7, 1.0, 1.2, 1.5, 1.7
Value range: 0.4 ≀ MinWidthSmooth ≀ 3.0 (lin)
Minimum increment: 0.01
Recommended increment: 0.1

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

Maximum width of Gauss operator for smoothing the curvature function.

Default: 2.42.4
Suggested values: 0.5, 0.7, 1.0, 1.2, 1.5, 1.70.5, 0.7, 1.0, 1.2, 1.5, 1.7
Value range: 0.4 ≀ MaxWidthSmooth ≀ 3.0 (lin)
Minimum increment: 0.01
Recommended increment: 0.1

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

Minimum width of curve area for curvature determination (\(>\) 0.4).

Default: 22
Suggested values: 2, 5, 72, 5, 7
Value range: 1 ≀ MinWidthCurve ≀ 12 (lin)
Minimum increment: 1
Recommended increment: 2

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

Maximum width of curve area for curvature determination.

Default: 1212
Suggested values: 2, 5, 72, 5, 7
Value range: 1 ≀ MaxWidthCurve ≀ 20 (lin)
Minimum increment: 1
Recommended increment: 2

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

Weighting factor for approximation precision.

Default: 1.01.0
Suggested values: 0.0, 0.5, 1.00.0, 0.5, 1.0
Value range: 0.0 ≀ Weight1 ≀ 1.0 (lin)
Minimum increment: 0.1
Recommended increment: 0.5

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

Weighting factor for large segments.

Default: 1.01.0
Suggested values: 0.0, 0.5, 1.00.0, 0.5, 1.0
Value range: 0.0 ≀ Weight2 ≀ 1.0 (lin)
Minimum increment: 0.1
Recommended increment: 0.5

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

Weighting factor for small segments.

Default: 1.01.0
Suggested values: 0.0, 0.5, 1.00.0, 0.5, 1.0
Value range: 0.0 ≀ Weight3 ≀ 1.0 (lin)
Minimum increment: 0.1
Recommended increment: 0.5

ArcCenterRowarcCenterRowarc_center_row (output_control) arc.center.y-array β†’ (integer)HTuple (Hlong)HTuple (int / long)Sequence[int]Htuple (Hlong)

Row of the center of an arc.

ArcCenterColarcCenterColarc_center_col (output_control) arc.center.x-array β†’ (integer)HTuple (Hlong)HTuple (int / long)Sequence[int]Htuple (Hlong)

Column of the center of an arc.

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

Angle of an arc.

ArcBeginRowarcBeginRowarc_begin_row (output_control) arc.begin.y-array β†’ (integer)HTuple (Hlong)HTuple (int / long)Sequence[int]Htuple (Hlong)

Row of the starting point of an arc.

ArcBeginColarcBeginColarc_begin_col (output_control) arc.begin.x-array β†’ (integer)HTuple (Hlong)HTuple (int / long)Sequence[int]Htuple (Hlong)

Column of the starting point of an arc.

LineBeginRowlineBeginRowline_begin_row (output_control) line.begin.y-array β†’ (integer)HTuple (Hlong)HTuple (int / long)Sequence[int]Htuple (Hlong)

Row of the starting point of a line segment.

LineBeginCollineBeginColline_begin_col (output_control) line.begin.x-array β†’ (integer)HTuple (Hlong)HTuple (int / long)Sequence[int]Htuple (Hlong)

Column of the starting point of a line segment.

LineEndRowlineEndRowline_end_row (output_control) line.end.y-array β†’ (integer)HTuple (Hlong)HTuple (int / long)Sequence[int]Htuple (Hlong)

Row of the ending point of a line segment.

LineEndCollineEndColline_end_col (output_control) line.end.x-array β†’ (integer)HTuple (Hlong)HTuple (int / long)Sequence[int]Htuple (Hlong)

Column of the ending point of a line segment.

Orderorderorder (output_control) integer-array β†’ (integer)HTuple (Hlong)HTuple (int / long)Sequence[int]Htuple (Hlong)

Sequence of line (value 0) and arc segments (value 1).

ExampleπŸ”—

(C)

/* read edge image  */
read_image(&Image,"fig1_kan")\;
/* construct edge region  */
hysteresis_threshold(Image,&RK1,64,255,40,1)\;
connection(RK1,&Rand)\;
/* fetch chain code  */
T_get_region_contour(Rand,&Rows,&Columns)\;
firstline = get_i(Tline,0)\;
firstcol = get_i(Tcol,0)\;
/* approximation with lines and circular arcs */
set_d(t1,0.4,0)\;
set_d(t2,2.4,0)\;

set_d(t3,0.3,0)\;
set_d(t4,0.9,0)\;

set_d(t5,0.2,0)\;

set_d(t6,0.4,0)\;
set_d(t7,2.4,0)\;

set_i(t8,2,0)\;
set_i(t9,12,0)\;

set_d(t10,1.0,0)\;
set_d(t11,1.0,0)\;
set_d(t12,1.0,0)\;

T_approx_chain(Rows,Columns,t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11,t12,
                &Bzl,&Bzc,&Br,&Bwl,&Bwc,&Ll0,&Lc0,&Ll1,&Lc1,&order)\;
nob = length_tuple(Bzl)\;
nol = length_tuple(Ll0)\;
/* draw lines and arcs */
set_i(WindowHandleTuple,WindowHandle,0)\;
set_line_width(WindowHandle,4)\;
if (nob>0) T_disp_arc(Bzl,Bzc,Br,Bwl,Bwc)\;
set_line_width(WindowHandle,1)\;
if (nol>0) T_disp_line(WindowHandleTuple,Ll0,Lc0,Ll1,Lc1)\;

ResultπŸ”—

The operator approx_chainApproxChain returns the value 2 (H_MSG_TRUE) if the parameters are correct. Otherwise an exception is raised.

Combinations with other operatorsπŸ”—

Combinations

Possible predecessors

sobel_ampSobelAmp, edges_imageEdgesImage, get_region_contourGetRegionContour, thresholdThreshold, hysteresis_thresholdHysteresisThreshold

Possible successors

set_line_widthSetLineWidth, disp_arcDispArc, disp_lineDispLine

Alternatives

get_region_polygonGetRegionPolygon, approx_chain_simpleApproxChainSimple

See also

get_region_chainGetRegionChain, smallest_circleSmallestCircle, disp_circleDispCircle, disp_lineDispLine

ModuleπŸ”—

Foundation