Effacer les filtres
Effacer les filtres

How to find the parabola using RANSAC method in Matlab

1 vue (au cours des 30 derniers jours)
vigneshwaran Loganathan
vigneshwaran Loganathan le 12 Juil 2018
Can anyone here suggest with ideas for finding the parabola using RANSAC where,
function [bestParameter1,bestParameter2] = ransac(data,num,iter,threshDist,inlierRatio
figure;plot(data(1,:),data(2,:),'o');hold on;
number = size(data,2); % Total number of points
bestInNum = 0; % Best fitting line with largest 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 points with the fitting line
kLine = sample(:,2)-sample(:,1);% two points relative distance
kLineNorm = kLine/norm(kLine);
normVector = [kLineNorm(2),-kLineNorm(1)];%Ax+By+C=0 A=-kLineNorm(2),B=kLineNorm(1)
distance = ((normVector)*(data - repmat(sample(:,1),1,number)));
%%Compute the inliers with distances smaller than the threshold
inlierIdx = find(abs(distance)<=threshDist);
inlierNum = length(inlierIdx);
%%Update the number of inliers and fitting model 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);
end
#Source from Wiki, In the above code the random points to be choosen is 3 instead 2 in my case(as i have to get Parabola and not the line) but the calculation of distance seems to be a problem. Can anyone help me with this?
Thank you so much for understanding in advance

Réponses (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by