算法 | RASAC 入门
=================================================
 博主github:https://github.com/MichaelBeechan
 博主CSDN:https://blog.csdn.net/u011344545
=================================================
 ?
塵世冰封的專欄_MJ卡爾曼的魚_CSDN博客-衛(wèi)星導航,程序語言設(shè)計(C語言、C++、Matlab等),MATLAB之計算機視覺與深度學習領(lǐng)域博主
RASAC——Wikipedia (Random sampleconsensus)
RASAC算法是一種學習技術(shù),通過隨機觀察樣本數(shù)據(jù)估計模型參數(shù)。給定一個數(shù)據(jù)集包含內(nèi)點和外點,RASAC使用投票方案找到優(yōu)化的擬合結(jié)果。數(shù)據(jù)集中的數(shù)據(jù)元素被用來投票給一個或多個模型。這個投票方案的實施基于兩個假設(shè):噪聲特征不會對任何單一模型(少數(shù)異常值)進行一致性投票;有足夠的特征得到好的模型(丟失數(shù)據(jù)少)。
RASAC算法主要由兩個步驟組成:
?????? 1.從輸入數(shù)據(jù)集中隨機抽取包含最小數(shù)據(jù)項的樣本子集。一個擬合模型和相應(yīng)的模型參數(shù)僅使用該樣本子集的元素來計算。樣本子集的基數(shù)足夠確定模型參數(shù)的最小值。
?????? 2.算法檢查整個數(shù)據(jù)集的那些元素和第一步獲得的模型參數(shù)所實例化的模型相一致。如果一個數(shù)據(jù)元素不符合由估計模型參數(shù)集合所實例化的擬合模型,那么它將被認為是一個異常值,該模型參數(shù)在一個誤差閾值內(nèi),定義了由噪聲影響引起的最大偏差。
?????? 擬合模型獲得的內(nèi)點集稱為一致集。RASAC反復迭代上述兩步,直到某些迭代中獲得足夠的內(nèi)點(一致集)。RASAC算法的輸入是一組觀測數(shù)據(jù)值。一種將某種模型擬合到觀測值的方法,以及一些置信參數(shù)。其通過重復以下步驟達到目標:
?????? 1.隨機選擇原始數(shù)據(jù)的一個子集,這個子集稱為假設(shè)內(nèi)點;
?????? 2.用一個模型擬合這個子集;
?????? 3.然后用這個模型測試所有的其他數(shù)據(jù),根據(jù)一些特定模型的損失函數(shù),這些點擬合了一個非常好的估計模型,而這些點被認為是一致集的一部分。
?????? 4.如果有足夠多的點被歸類為一致集的一部分,那么這個估計模型就相當不錯。
?????? 5.然后,使用一致集的所有元素重新估計,來改進模型。
這個過程重復固定的次數(shù),每次都產(chǎn)生一個被拒絕的模型,因為太少的點是一致集的一部分,或者是一個改進的模型和其相應(yīng)的一致集的大小的原因。在后一種情況下,如果它的一致集比先前保存的模型大,我們就保留了這個改進的模型。
MATLAB實現(xiàn)過程
function [bestParameter1,bestParameter2]= ransac_demo(data,num,iter,threshDist,inlierRatio)
?% data: a 2xn dataset with #n data points
?% num: the minimum number of points. Forline fitting problem, num=2
?% iter: the number of iterations
?% threshDist: the threshold of thedistances between points and the fitting line
?% inlierRatio: the threshold of the numberof inliers
?%% Plot the data points
?figure;plot(data(1,:),data(2,:),'o');hold on;
?number = size(data,2); % Total number ofpoints
?bestInNum = 0; % Best fitting line withlargest number of inliers
?bestParameter1=0;bestParameter2=0; %parameters for best fitting line
?for i=1:iter
?%% Randomly select 2 points
???? idx = randperm(number,num); sample = data(:,idx);??
?%% Compute the distances between all pointswith the fitting line
???? kLine = sample(:,2)-sample(:,1);% twopoints relative distance
???? kLineNorm = kLine/norm(kLine);
???? normVector = [-kLineNorm(2),kLineNorm(1)];%Ax+By+C=0A=-kLineNorm(2),B=kLineNorm(1)
???? distance = normVector*(data - repmat(sample(:,1),1,number));
?%% Compute the inliers with distancessmaller than the threshold
???? inlierIdx = find(abs(distance)<=threshDist);
???? inlierNum = length(inlierIdx);
?%% Update the number of inliers and fittingmodel if better model is found????
???? if inlierNum>=round(inlierRatio*number)&& inlierNum>bestInNum
???????? bestInNum = inlierNum;
???????? parameter1 = (sample(2,2)-sample(2,1))/(sample(1,2)-sample(1,1));
???????? parameter2 = sample(2,1)-parameter1*sample(1,1);
???????? bestParameter1=parameter1; bestParameter2=parameter2;
???? end
?end
?%% Plot the best fitting line
?xAxis = -number/2:number/2;
?yAxis = bestParameter1*xAxis + bestParameter2;
?plot(xAxis,yAxis,'r-','LineWidth',2);
RASAC的缺點是:
?????? 1.時間沒有上限
?????? 2.閾值設(shè)置問題(要求設(shè)置特定的閾值)
總結(jié)
以上是生活随笔為你收集整理的算法 | RASAC 入门的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
 
                            
                        - 上一篇: Python练习 | 初识Python、
- 下一篇: OpenCV | 双目相机标定之Open
