spline interpolation image way to connect ?
Afficher commentaires plus anciens
hi i try to make spline interpolation between two curves but i get bad results any help ?
i want to connect blue and red curves. i try to remove the unique values get bad result of yellow line
build problemz=zeros(1000,1000);
figure(1)
imshow(z);
vv =[801 928
748 923
687 902
657 854
651 814
657 785
671 730
700 695];
hold on,plot(vv(:,1),vv(:,2),'r'),plot(vv(:,1),vv(:,2),'r*')
vf =[800 328
801 306
805 256
798 223];
plot(vf(:,1),vf(:,2),'b'),plot(vf(:,1),vf(:,2),'b*')
%% point vector
xxa=[vv(:,1);vf(:,1)];
yya=[vv(:,2);vf(:,2)];
[w1,id2,idx]=unique(xxa,'stable');
xxas=xxa(id2);yyas=yya(id2);
dataPoints=[xxa,yya];
plot(dataPoints(:,1),dataPoints(:,2),'ko')
plot(dataPoints(:,1),dataPoints(:,2),'ko')
distF=[0 ;sqrt(sum(diff(dataPoints).^2,2))];
distFSum=cumsum(distF);
figure(2),plot(distF);grid on;title('distance between points')
figure(3),plot(distFSum);grid on;title('sum distance between points')
%% spline
sx=spline(xxas,distFSum(id2),linspace(min(xxa),max(xxa),100));
sy=spline(yyas,distFSum(id2),linspace(min(yya),max(yya),100));
figure(1)
plot(sx,sy,'y','LineWidth',2)
Réponse acceptée
Plus de réponses (1)
darova
le 23 Juil 2019
When you have a curve something like this and want to get smooth red curve

You do
x = [x1 x2 ... xn] % all X data
y = [y1 y2 ... yn] % all Y data
xr = linspace(x4,x5,10); % i want 10 points for red curve (between 4 and 5 vertices)
yr = spline(x,y,xr);
You just have to switch X and Y for your case (because your curve is vertical)
Catégories
En savoir plus sur Multirate Signal Processing dans Centre d'aide et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
