Bonjour

j'ai un petit souci concernant l'interpolation :

pour bien expliquer ma problématique, j'ai préparé un petit exemple avec une matrice de zéros appelée "a" de dimension 40*40,
j'ai inséré des "1" leurs coordonnées sont les vecteurs x et y, afin de constituer un petit contour blanc fermé ,
Problématique: je voudrai lié entre ces points afin de l'utiliser comme contour dans une autre fonction, ('snackedeform')
j'ai essayer avec l'instruction 'interp1' mais ça donne des liaisons linéaires aléatoires ( bon par rapport ce que je veux)
je veux que chaque point se lie avec le point voisin et de continuer dans la même direction

bref voila le code

Code : Sélectionner tout - Visualiser dans une fenêtre à part
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

et voila les fonctions utilisées
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
function y = snakeindex(IDX)
% SNAKEINDEX  Create index for adpative interpolating the snake 
%     y = snakeindex(IDX)
%
 
N = length(IDX);
y=1:0.5:N+0.5;
x=1:N;
y(2*x(IDX==0))=[];

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
function snakedisp(x,y,style)
% SNAKEDISP  Initialize the snake 
%      snakedisp(x,y,line)
%       
%      style is same as the string for plot
 
%      Chenyang Xu and Jerry L. Prince, 5/15/95, 6/17/97
%      Copyright (c) 1995-97 by Chenyang Xu and Jerry L. Prince
%      Image Analysis and Communications Lab, Johns Hopkins University
 
hold on
 
% convert to column data
x = x(:); y = y(:);
 
if nargin == 3
   plot([x;x(1,1)],[y;y(1,1)],style);
   hold off
else
   disp('snakedisp.m: The input parameter is not correct!'); 
end
j'espère que je trouverai de solution ici, Merci d'avance