approx_chainT_approx_chainApproxChainApproxChainapprox_chain近似链(算子)

名称

approx_chainT_approx_chainApproxChainApproxChainapprox_chain — 用圆弧和线近似轮廓。

警告

approx_chainapprox_chainApproxChainApproxChainApproxChainapprox_chain 已过时,仅出于向后兼容性考虑而保留。

签名

approx_chain( : : Row, Column, MinWidthCoord, MaxWidthCoord, ThreshStart, ThreshEnd, ThreshStep, MinWidthSmooth, MaxWidthSmooth, MinWidthCurve, MaxWidthCurve, Weight1, Weight2, Weight3 : ArcCenterRow, ArcCenterCol, ArcAngle, ArcBeginRow, ArcBeginCol, LineBeginRow, LineBeginCol, LineEndRow, LineEndCol, Order)

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)

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

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)

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]]

描述

曲线的坐标通过一系列线和弧进行近似。该函数会为特定参数尝试用户可定义范围内的数值。这些范围的边界在函数的参数列表中明确标注 (MinWidthCoord ... MaxWidthCoord, ThreshStart ... ThreshEnd, MinWidthSmooth ... MaxWidthSmooth, MinWidthCurve ... MaxWidthCurve)。此外需指定角点阈值参数区域的步长(ThreshStep)。通过缩小覆盖范围可缩短计算时间,但可能导致结果质量下降。

参数 Weight1、Weight2 和 Weight3 分别指示期望的权重分配方向:侧重于逼近精度、尽可能获得更多大段,还是尽可能减少小段。因此,当 (Weight1,Weight2,Weight3) 取值为 (1,0,0) 时,将生成高度精确的逼近结果;而取值为 (0,1,1) 时,则会生成尽可能减少大段的逼近结果。

该函数的结果将弧和线分别返回。若需获取线段序列,可从返回元组中依次读取各个结果元素;序列可通过返回参数 order(0:下一个元素为下一条线段;1:下一个元素为下一条弧段)获取。

注意

可能仅由单个段构成的轮廓也应采用阈值最大值(ThreshEnd)> 1.0 进行检查,否则无论如何都会确定至少一个“角点”。

执行信息

参数

RowRowRowRowrowrow (输入控制)  point.y-array HTupleSequence[int]HTupleHtuple (integer) (int / long) (Hlong) (Hlong)

轮廓的行。

默认值: 32

ColumnColumnColumnColumncolumncolumn (输入控制)  point.x-array HTupleSequence[int]HTupleHtuple (integer) (int / long) (Hlong) (Hlong)

轮廓的列。

默认值: 32

MinWidthCoordMinWidthCoordMinWidthCoordMinWidthCoordminWidthCoordmin_width_coord (输入控制)  real HTuplefloatHTupleHtuple (real) (double) (double) (double)

用于坐标平滑处理的高斯算子的最小宽度(> 0.4)。

默认值: 0.5

建议值: 0.5, 0.7, 1.0, 1.2, 1.5, 1.7

值范围: 0.4 ≤ MinWidthCoord MinWidthCoord MinWidthCoord MinWidthCoord minWidthCoord min_width_coord ≤ 3.0 (lin)

最小增量: 0.01

建议增量: 0.1

MaxWidthCoordMaxWidthCoordMaxWidthCoordMaxWidthCoordmaxWidthCoordmax_width_coord (输入控制)  real HTuplefloatHTupleHtuple (real) (double) (double) (double)

用于坐标平滑处理的高斯算子的最大宽度(> 0.4)。

默认值: 2.4

建议值: 0.5, 0.7, 1.0, 1.2, 1.5, 1.7

值范围: 0.4 ≤ MaxWidthCoord MaxWidthCoord MaxWidthCoord MaxWidthCoord maxWidthCoord max_width_coord ≤ 3.0 (lin)

最小增量: 0.01

建议增量: 0.1

ThreshStartThreshStartThreshStartThreshStartthreshStartthresh_start (输入控制)  real HTuplefloatHTupleHtuple (real) (double) (double) (double)

接受角点的曲率最小阈值(相对于存在的最大曲率)。

默认值: 0.3

建议值: 0.3, 0.4, 0.5, 0.6, 0.7, 0.8

值范围: 0.1 ≤ ThreshStart ThreshStart ThreshStart ThreshStart threshStart thresh_start ≤ 0.9 (lin)

最小增量: 0.01

建议增量: 0.1

ThreshEndThreshEndThreshEndThreshEndthreshEndthresh_end (输入控制)  real HTuplefloatHTupleHtuple (real) (double) (double) (double)

接受角点的曲率最大阈值(相对于存在的最大曲率)。

默认值: 0.9

建议值: 0.3, 0.4, 0.5, 0.6, 0.7, 0.8

值范围: 0.1 ≤ ThreshEnd ThreshEnd ThreshEnd ThreshEnd threshEnd thresh_end ≤ 0.9 (lin)

最小增量: 0.01

建议增量: 0.1

ThreshStepThreshStepThreshStepThreshStepthreshStepthresh_step (输入控制)  real HTuplefloatHTupleHtuple (real) (double) (double) (double)

阈值增量的步长。

默认值: 0.2

建议值: 0.3, 0.4, 0.5

值范围: 0.1 ≤ ThreshStep ThreshStep ThreshStep ThreshStep threshStep thresh_step ≤ 0.9 (lin)

最小增量: 0.01

建议增量: 0.1

MinWidthSmoothMinWidthSmoothMinWidthSmoothMinWidthSmoothminWidthSmoothmin_width_smooth (输入控制)  real HTuplefloatHTupleHtuple (real) (double) (double) (double)

用于平滑曲率函数的高斯算子的最小宽度(> 0.4)。

默认值: 0.5

建议值: 0.5, 0.7, 1.0, 1.2, 1.5, 1.7

值范围: 0.4 ≤ MinWidthSmooth MinWidthSmooth MinWidthSmooth MinWidthSmooth minWidthSmooth min_width_smooth ≤ 3.0 (lin)

最小增量: 0.01

建议增量: 0.1

MaxWidthSmoothMaxWidthSmoothMaxWidthSmoothMaxWidthSmoothmaxWidthSmoothmax_width_smooth (输入控制)  real HTuplefloatHTupleHtuple (real) (double) (double) (double)

用于平滑曲率函数的高斯算子的最大宽度。

默认值: 2.4

建议值: 0.5, 0.7, 1.0, 1.2, 1.5, 1.7

值范围: 0.4 ≤ MaxWidthSmooth MaxWidthSmooth MaxWidthSmooth MaxWidthSmooth maxWidthSmooth max_width_smooth ≤ 3.0 (lin)

最小增量: 0.01

建议增量: 0.1

MinWidthCurveMinWidthCurveMinWidthCurveMinWidthCurveminWidthCurvemin_width_curve (输入控制)  integer HTupleintHTupleHtuple (integer) (int / long) (Hlong) (Hlong)

用于测定曲率的曲线区域的最小宽度(> 0.4)。

默认值: 2

建议值: 2, 5, 7

值范围: 1 ≤ MinWidthCurve MinWidthCurve MinWidthCurve MinWidthCurve minWidthCurve min_width_curve ≤ 12 (lin)

最小增量: 1

建议增量: 2

MaxWidthCurveMaxWidthCurveMaxWidthCurveMaxWidthCurvemaxWidthCurvemax_width_curve (输入控制)  integer HTupleintHTupleHtuple (integer) (int / long) (Hlong) (Hlong)

用于测定曲率的曲线区域的最大宽度。

默认值: 12

建议值: 2, 5, 7

值范围: 1 ≤ MaxWidthCurve MaxWidthCurve MaxWidthCurve MaxWidthCurve maxWidthCurve max_width_curve ≤ 20 (lin)

最小增量: 1

建议增量: 2

Weight1Weight1Weight1Weight1weight1weight_1 (输入控制)  real HTuplefloatHTupleHtuple (real) (double) (double) (double)

用于近似精度的权重系数。

默认值: 1.0

建议值: 0.0, 0.5, 1.0

值范围: 0.0 ≤ Weight1 Weight1 Weight1 Weight1 weight1 weight_1 ≤ 1.0 (lin)

最小增量: 0.1

建议增量: 0.5

Weight2Weight2Weight2Weight2weight2weight_2 (输入控制)  real HTuplefloatHTupleHtuple (real) (double) (double) (double)

用于大段的权重系数。

默认值: 1.0

建议值: 0.0, 0.5, 1.0

值范围: 0.0 ≤ Weight2 Weight2 Weight2 Weight2 weight2 weight_2 ≤ 1.0 (lin)

最小增量: 0.1

建议增量: 0.5

Weight3Weight3Weight3Weight3weight3weight_3 (输入控制)  real HTuplefloatHTupleHtuple (real) (double) (double) (double)

用于小段的权重系数。

默认值: 1.0

建议值: 0.0, 0.5, 1.0

值范围: 0.0 ≤ Weight3 Weight3 Weight3 Weight3 weight3 weight_3 ≤ 1.0 (lin)

最小增量: 0.1

建议增量: 0.5

ArcCenterRowArcCenterRowArcCenterRowArcCenterRowarcCenterRowarc_center_row (输出控制)  arc.center.y-array HTupleSequence[int]HTupleHtuple (integer) (int / long) (Hlong) (Hlong)

弧中心的行。

ArcCenterColArcCenterColArcCenterColArcCenterColarcCenterColarc_center_col (输出控制)  arc.center.x-array HTupleSequence[int]HTupleHtuple (integer) (int / long) (Hlong) (Hlong)

弧中心的列。

ArcAngleArcAngleArcAngleArcAnglearcAnglearc_angle (输出控制)  arc.angle.rad-array HTupleSequence[float]HTupleHtuple (real) (double) (double) (double)

弧角度。

ArcBeginRowArcBeginRowArcBeginRowArcBeginRowarcBeginRowarc_begin_row (输出控制)  arc.begin.y-array HTupleSequence[int]HTupleHtuple (integer) (int / long) (Hlong) (Hlong)

弧起点的行。

ArcBeginColArcBeginColArcBeginColArcBeginColarcBeginColarc_begin_col (输出控制)  arc.begin.x-array HTupleSequence[int]HTupleHtuple (integer) (int / long) (Hlong) (Hlong)

弧起点的列。

LineBeginRowLineBeginRowLineBeginRowLineBeginRowlineBeginRowline_begin_row (输出控制)  line.begin.y-array HTupleSequence[int]HTupleHtuple (integer) (int / long) (Hlong) (Hlong)

线段起点的行。

LineBeginColLineBeginColLineBeginColLineBeginCollineBeginColline_begin_col (输出控制)  line.begin.x-array HTupleSequence[int]HTupleHtuple (integer) (int / long) (Hlong) (Hlong)

线段起点的列。

LineEndRowLineEndRowLineEndRowLineEndRowlineEndRowline_end_row (输出控制)  line.end.y-array HTupleSequence[int]HTupleHtuple (integer) (int / long) (Hlong) (Hlong)

线段终点的行。

LineEndColLineEndColLineEndColLineEndCollineEndColline_end_col (输出控制)  line.end.x-array HTupleSequence[int]HTupleHtuple (integer) (int / long) (Hlong) (Hlong)

线段终点的列。

OrderOrderOrderOrderorderorder (输出控制)  integer-array HTupleSequence[int]HTupleHtuple (integer) (int / long) (Hlong) (Hlong)

由线(值为 0)和弧(值为 1)组成的序列。

示例(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);

结果

算子 approx_chainapprox_chainApproxChainApproxChainApproxChainapprox_chain 在参数正确时返回值 2 ( H_MSG_TRUE )。否则将抛出异常。

可能的前趋

sobel_ampsobel_ampSobelAmpSobelAmpSobelAmpsobel_amp, edges_imageedges_imageEdgesImageEdgesImageEdgesImageedges_image, get_region_contourget_region_contourGetRegionContourGetRegionContourGetRegionContourget_region_contour, thresholdthresholdThresholdThresholdThresholdthreshold, hysteresis_thresholdhysteresis_thresholdHysteresisThresholdHysteresisThresholdHysteresisThresholdhysteresis_threshold

可能的后继

set_line_widthset_line_widthSetLineWidthSetLineWidthSetLineWidthset_line_width, disp_arcdisp_arcDispArcDispArcDispArcdisp_arc, disp_linedisp_lineDispLineDispLineDispLinedisp_line

替代

get_region_polygonget_region_polygonGetRegionPolygonGetRegionPolygonGetRegionPolygonget_region_polygon, approx_chain_simpleapprox_chain_simpleApproxChainSimpleApproxChainSimpleApproxChainSimpleapprox_chain_simple

另见

get_region_chainget_region_chainGetRegionChainGetRegionChainGetRegionChainget_region_chain, smallest_circlesmallest_circleSmallestCircleSmallestCircleSmallestCirclesmallest_circle, disp_circledisp_circleDispCircleDispCircleDispCircledisp_circle, disp_linedisp_lineDispLineDispLineDispLinedisp_line

模块

基础