主要内容

fitPolynomialRANSAC

Fit polynomial to points using RANSAC

描述

example

P= fitPolynomialRANSAC(xyPoints,N,MaxDistance)找到多项式系数,P,通过抽样一组给出的点xyPointsand generating polynomial fits. The fit that has the most inliers withinMaxDistanceis returned. If a fit cannot be found, thenP该函数使用M估计器样品共识(MSAC)算法,这是随机样品共识(RANSAC)算法的变体来拟合数据。

[P,inlierIdx] = fitpolynomialransac(___)returns a logical array,inlierIdx,这指定了基于拟合多项式的数据点的索引MaxDistance。采用the input arguments from the previous syntax.

[___] = fitpolynomialransac(___,名称,值)指定一个或多个指定的其他选项Name,Value配对参数。

例子

全部收缩

使用RANSAC算法生成适合一组嘈杂数据的多项式。这fitPolynomialRANSAC函数通过从中抽样一组点来生成多项式[x y]点数据并生成多项式拟合。与最渗透器的拟合MaxDistanceis returned.

[x y]点。

x = (-10:0.1:10)'; y = (36-x.^2)/9; figure plot(x,y) title('Parabola')

图包含一个轴对象。这axes object with title Parabola contains an object of type line.

将噪音和离群值添加到抛物线的点上。

y = y+rand(length(y),1); y([50,150,99,199]) = [y(50)+12,y(150)-12,y(99)+33,y(199)-23]; plot(x,y) title(“与异常值和噪音的抛物线”)

图包含一个轴对象。这axes object with title Parabola with Outliers and Noise contains an object of type line.

采用fitPolynomialRANSAC生成二级多项式的系数。还要获取指定的嵌入器MaxDistance从多项式拟合。

n = 2;%二级多项式MaxDistance= 1;% maximum allowed distance for a point to be inlier[P, inlierIdx] = fitPolynomialRANSAC([x,y],N,maxDistance);

Evaluate the polynomial using多腔。绘制曲线并覆盖[x y]点。Mark outliers with a red circle.

yrecoveredCurve = polyVal(p,x);图图(x,yrecoveredcurve,'-g','LineWidth',3) holdplot(x(inlierIdx),y(inlierIdx),'.',x(〜inlieridx),y(〜inlieridx),'ro') legend('Fit polynomial',“进点”,“离群值点”) 抓住离开

图包含一个轴对象。轴对象包含3个类型行的对象。这些对象代表拟合多项式,局部点,离群点。

Input Arguments

全部收缩

[x y]坐标点,指定为m-by-2矩阵。多项式适合这些点。

Data Types:双倍的|single|uint32|INT32|UINT16|INT16

多项式拟合度,P, specified as an integer. The degree of a polynomial is the highest degree of the terms in the equation. For example, a polynomial of degree 2 is:

Ax2+Bx+C

A,B, 和Care constants. In general, higher degree polynomials allow for a better fit, but the fit depends on your data.

Maximum distance from the polynomial fit curve to an inlier point, specified as a positive scalar. Any points further away are considered outliers. The RANSAC algorithm creates a fit from a small sample of points but tries to maximize the number of inlier points. Lowering the maximum distance helps to improve the polynomial fit by putting a tighter tolerance on inlier points.

Name-Value Arguments

Specify optional comma-separated pairs ofName,Value参数。Nameis the argument name and价值是相应的值。Name必须出现在引号中。您可以按任何顺序指定几个名称和值对参数NAME1,Value1,...,Namen,Valuen

例子:'MaxNumTrials',2000

Maximum number of random trials, specified as the comma-separated pair consisting of 'MaxNumTrials'和一个整数。一次试验使用最少数量的随机点xyPointsto fit a parabolic model. Then, the trial checks the number of inliers within theMaxDistance从模型。在所有试验之后,选择了嵌入式数量最高的模型。增加试验的数量可以以其他计算为代价提高产出的鲁棒性。

最终解决方案发现多项式拟合的最大嵌入式数量的信心,该拟合物指定为逗号分隔对,由'Confidence' and a scalar from 0 to 100. Increasing this value improves the robustness of the output at the expense of additional computation.

验证多项式的功能, specified as the comma-separated pair consisting of 'ValidatePolynomialFcn' and a function handle. The function returns真的如果根据函数中定义的标准接受多项式。使用此功能拒绝特定的多项式拟合。该功能必须是形式:

isValid = validatePolynomialFcn(P,varargin)

如果未指定函数,则假定所有多项式都是有效的。

最大数量的尝试找到有效多项式的样本,该样本指定为逗号分隔对,由'MaxSmplingAttsment'和一个整数。

Output Arguments

全部收缩

Polynomial coefficients, returned as a vector of numeric scalars. Each element corresponds to a constant in the polynomial equation with degreeN。For example, for a second-degree polynomial,Ax2+Bx+C:

P = [A B C];

Data Types:single|双倍的

Inlier点,作为逻辑向量返回。向量的长度与xyPoints,并且每个元素指示该点是否是基于多项式拟合的局面MaxDistance

参考

[1] Torr, P. H. S., and A. Zisserman. "MLESAC: A New Robust Estimator with Application to Estimating Image Geometry."Computer Vision and Image Understanding。Vol. 18, Issue 1, April 2000, pp. 138–156.

Introduced in R2017a