1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
| tic
a=zeros(40,40);
a(10,10:1:12)=1;
a(11,10)=1;
a(11,12)=1;
a(12,10)=1;
a(12,12)=1;
a(13,10:1:12)=1;
imshow(a);
x=[10 10 10 11 11 12 13 13 13 13];
y=[10 11 12 10 12 10 12 10 11 12];
dmax=2;
dmin=0.5;
%[x,y] = snakeinterp(x,y,2,0.5);
%%%%%%%%%%%
%SNAKEINTERP Interpolate the snake adaptively
% [xi,yi] = snakeinterp(x,y,dmax,dmin)
%
% dmax: the maximum distance between two snake points
% dmin: the minimum distance between two snake points
% d(i,i+1)>dmax, then a new point is added between i and i+1
% d(i,i+1)<dmin, then either i or i+1 is removed
%
% NOTE: the spacing of original curve must be close to the
% range defined by dmax and dmin. For arbitrary spacing,
% try snakeinterp1.
%
% See also SNAKEINTERP1
% there is a bug in the program for points removal
% Chenyang Xu and Jerry L. Prince, 4/1/95, 6/17/97
% Copyright (c) 1995-97 by Chenyang Xu and Jerry L. Prince
% Image Analysis and Communications Lab, Johns Hopkins University
% convert to column vector
x = x(:); y = y(:);
N = length(x);
d = abs(x([2:N 1])- x(:)) + abs(y([2:N 1])- y(:));
% remove the points which distance to neighbor points is shorter than dmin
IDX = (d<dmin);
idx = find(IDX==0);
x = x(idx);
y = y(idx);
N = length(x);
d = abs(x([2:N 1])- x(:)) + abs(y([2:N 1])- y(:));
IDX = (d>dmax);
z = snakeindex(IDX);
p = 1:N+1;
xi = interp1(p,[x;x(1)],z');
yi = interp1(p,[y;y(1)],z');
N = length(xi);
d = abs(xi([2:N 1])- xi(:)) + abs(yi([2:N 1])- yi(:));
while (max(d)>dmax),
IDX = (d>dmax);
z = snakeindex(IDX);
p = 1:N+1;
xi = interp1(p,[xi;xi(1)],z','spline');
%%%%%
%%%%%
yi = interp1(p,[yi;yi(1)],z','spline');
N = length(xi);
d = abs(xi([2:N 1])- xi(:)) + abs(yi([2:N 1])- yi(:));
end
x=xi;
y=yi;
%%%%%%%%%%%
snakedisp(x,y,'r');
toc |
Partager