]> AND Private Git Repository - these_gilles.git/blob - THESE/codes/meanshift/Ms_segmenter/Fit_spline.m
Logo AND Algorithmique Numérique Distribuée

Private GIT Repository
7 avril pour jury
[these_gilles.git] / THESE / codes / meanshift / Ms_segmenter / Fit_spline.m
1 function Dense_pts = Fit_spline (Pts)\r
2 \r
3 Xdata = Pts(1, :);\r
4 Ydata = Pts(2, :);\r
5 \r
6 % making splines separately for X and Y, but with common parameter\r
7 Length = 0;\r
8 Param(1) = Length;\r
9 for i=1:length(Xdata)-1\r
10         Length = Length + norm(Pts(:, i+1) - Pts(:, i));\r
11         Param(i+1) = Length;\r
12 end\r
13 \r
14 % sampling at a dense set of points\r
15 Gridpts = [min(Param):0.1:max(Param)];\r
16 Xspline = round(spline(Param, Xdata, Gridpts));\r
17 Yspline = round(spline(Param, Ydata, Gridpts));\r
18 \r
19 % if not sufficiently dense, adjusting those\r
20 k = 0;  Dense_pts = zeros(2, 0);\r
21 for i=1:length(Xspline)-1\r
22         if max(abs(Xspline(i+1)-Xspline(i)), abs(Yspline(i+1)-Yspline(i))) > 1\r
23                 for j=0:abs(Xspline(i+1)-Xspline(i))\r
24                         k = k+1;\r
25                         Dense_pts(:, k) = [Xspline(i) + j*sign(Xspline(i+1)-Xspline(i)); ...\r
26                                 Yspline(i)];\r
27                 end\r
28                 for j=0:abs(Yspline(i+1)-Yspline(i))\r
29                         k = k+1;\r
30                         Dense_pts(:, k) = [Xspline(i+1); ...\r
31                                 Yspline(i) + j*sign(Yspline(i+1)-Yspline(i))];\r
32                 end\r
33          else\r
34                 k = k+1;\r
35                 Dense_pts(:, k) = [Xspline(i); Yspline(i)];\r
36         end\r
37 end\r