RANSAC与LSP

最近又要用到ransac算法,之前学过也用过,但是好久没用,只知道是干什么用的,现在来重新总结一下,再来复习一遍:

       Ransac和最小二乘法都用于模型的最优估计;RANSAC是考虑局部有用的那些数据,取有用数据的模型;LSP考虑的是全局数据,取全局误差最小的模型

一、基础原理:

RANSAC:称为随机抽样一致算法(random sample consensus,RANSAC),采用迭代的方式从一组包含outliers(离群)的被观测数据中估算出最优inliers数学模型。

算法简介:RANSAC算法的基本假设是样本中包含正确数据(inliers,可以被模型描述的数据),也包含异常数据(outliers,偏离正常范围很远、无法适应数学模型的数据),即数据集中含有噪声。这些异常数据可能是由于错误的测量、错误的假设、错误的计算等产生的。同时RANSAC也假设,给定一组正确的数据,存在可以计算出符合这些数据的模型参数的方法。

使用条件:1).一组带噪声的观测数据,其中的inliers数据占了大多数;2).有一个可以解释可信观测数据的参数化模型

二、对比:

最小二乘法(LSP):是从全局出发,考虑所有数据,从所有数据中估计出一个整体误差最小的模型,默认为所有的数据都为inliers,都会参与建模;

RANSAC:算法是从一堆数据中选择出某一个模型,前提是假设这组数据有某种特性,数据里有inliers和outliers,也就是在建模的数据中掺杂着噪声数据,在建模的是时候应该剔除这些噪声数据,仅选择inliers数据来建模,这是和LSP最本质的区别;

假设一组数据符合一个直线模型:y=ax+b,用最小二乘就可以很容易求解出未知参数a和b。


当观测的数据充满了噪声时,比如下面图中的黑点,很明显中间有一条直线,但是用最小二乘去解它,于是出问题啦:

很显然最小二乘失效了,这时候就要用RANSAC去解决它。

 

RANSAC的算法大致可以表述为(来自wikipedia):
Given:
    data – a set of observed data points
    model – a model that can be fitted to data points
    n – the minimum number of data values required to fit the model
    k – the maximum number of iterations allowed in the algorithm
    t – a threshold value for determining when a data point fits a model
    d – the number of close data values required to assert that a model fits well to data

Return:
    bestfit – model parameters which best fit the data (or nul if no good model is found)

iterations = 0
bestfit = nul
besterr = something really large
while iterations < k {
    maybeinliers = n randomly selected values from data
    maybemodel = model parameters fitted to maybeinliers
    alsoinliers = empty set
    for every point in data not in maybeinliers {
        if point fits maybemodel with an error smaller than t
             add point to alsoinliers
    }
    if the number of elements in alsoinliers is > d {
        % this implies that we may have found a good model
        % now test how good it is
        bettermodel = model parameters fitted to all points in maybeinliers and alsoinliers
        thiserr = a measure of how well model fits these points
        if thiserr < besterr {
            bestfit = bettermodel
            besterr = thiserr
        }
    }
    increment iterations
}
return bestfit

三、RANSAC应用简介

RANSAC其实就是一种采样方式,例如在图像拼接(Image stitching)技术中:

第一步:预处理后(据说桶形变换,没有去了解过)提取图像特征(如SIFT


第二步:特征点进行匹配,可利用归一化互相关(NormalizedCross Correlation method, NCC)等方法。

但这个时候会有很多匹配错误的点:


这就好比拟合曲线,有很多的误差点,这个时候就想到了RANSAC算法:我不要再兼顾所有了,每次选取Nums个点匹配计算匹配后容差范围内的点数重复实验,迭代结束后,找出点数最多的情况,就是最优的匹配。 

利用RANSAC匹配:


第三步:图像拼接,这个就涉及拼接技术了,直接给出结果:

 

 

 

 参考:

https://en.wikipedia.org/wiki/Random_sample_consensus

https://blog.csdn.net/zinnc/article/details/52319716

https://www.cnblogs.com/xingshansi/p/6763668.html

https://blog.csdn.net/laobai1015/article/details/51682596

 

 


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值