1 function K=InterpolateContourPoints2D(P,nPoints)
\r
2 % This function resamples a few points describing a countour , to a smooth
\r
3 % contour of uniform sampled points.
\r
5 % K=InterpolateContourPoints(P,nPoints)
\r
8 % P : Inpute Contour, size N x 2 (with N>=4)
\r
9 % nPoints : Number of Contour points as output
\r
12 % K : Uniform sampled Contour points, size nPoints x 2
\r
14 % Function is written by D.Kroon University of Twente (July 2010)
\r
18 % figure, imshow(imread('moon.tif'));
\r
19 % % Select some points with the mouse
\r
21 % % Make an array with the clicked coordinates
\r
23 % % Interpolate inbetween the points
\r
24 % Pnew=InterpolateContourPoints2D(P,100)
\r
26 % hold on; plot(P(:,2),P(:,1),'b*');
\r
27 % plot(Pnew(:,2),Pnew(:,1),'r.');
\r
29 % Function is written by D.Kroon University of Twente (July 2010)
\r
31 % Interpolate points inbetween
\r
32 O(:,1)=interp([P(end-3:end,1);P(:,1);P(:,1);P(1:4,1)],10);
\r
33 O(:,2)=interp([P(end-3:end,2);P(:,2);P(:,2);P(1:4,2)],10);
\r
36 % Calculate distance between points
\r
37 dis=[0;cumsum(sqrt(sum((O(2:end,:)-O(1:end-1,:)).^2,2)))];
\r
39 % Resample to make uniform points
\r
40 K(:,1) = interp1(dis,O(:,1),linspace(0,dis(end),nPoints*2));
\r
41 K(:,2) = interp1(dis,O(:,2),linspace(0,dis(end),nPoints*2));
\r
42 K=K(round(end/4):round(end/4)+nPoints-1,:);
\r