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

Private GIT Repository
final
[these_gilles.git] / THESE / codes / meanshift / Ms_segmenter / M_shift2.m
1 function [Mode, Number_values] = M_shift2 (Values, Window_radius, Initial, Mv)\r
2 % assumes that Values contains cumulative information, i.e.\r
3 % the number of elements of the particular value in each Values cell\r
4 \r
5 Current_val = round(Initial+2);\r
6 Next_val = round(Initial);\r
7 L1 = size(Values, 1);  L2 = size(Values, 2);\r
8 \r
9 % global plot_number plot_xmin plot_xmax plot_ymin plot_ymax\r
10 % if plot_number == 1\r
11 %       figure;\r
12 % end\r
13 % [II, JJ] = find(Values > 0);\r
14 % if plot_number == 1\r
15 %       plot_xmin = min(II)-Window_radius/2;\r
16 %       plot_xmax = max(II)+Window_radius/2;\r
17 %       plot_ymin = min(JJ)-Window_radius/2;\r
18 %       plot_ymax = max(JJ)+Window_radius/2;\r
19 % end\r
20\r
21 % subplot(2, 2, plot_number);\r
22 % plot(II, JJ, '.');\r
23 % xlabel('first principal component');\r
24 % ylabel('second prrincipal component');\r
25 % axis([plot_xmin plot_xmax plot_ymin plot_ymax])\r
26 % text(Next_val(1)+Window_radius/1.8, Next_val(2)-Window_radius/4, 'Initial');\r
27 \r
28 while norm(Next_val-Current_val) > 2\r
29 \r
30 %       Draw_rect(Window_radius, Window_radius, Next_val, 'magenta');\r
31 \r
32         Current_val = Next_val;\r
33         clear x;\r
34    Window = Values(...\r
35                 max(1, Current_val(1)-Window_radius): ...\r
36       min(L1, Current_val(1)+Window_radius), ...\r
37                 max(1, Current_val(2)-Window_radius): ...\r
38                 min(L2, Current_val(2)+Window_radius));\r
39         [x(1, :, :), x(2, :, :)] = ...\r
40       ndgrid(...\r
41       [max(1, Current_val(1)-Window_radius): ...\r
42       min(L1, Current_val(1)+Window_radius)], ...\r
43       [max(1, Current_val(2)-Window_radius): ...\r
44       min(L2, Current_val(2)+Window_radius)]);\r
45 \r
46         for i=1:2\r
47                 Sum_values(1, i) = sum(sum(squeeze(x(i, :, :)) .* Window));\r
48         end\r
49    Number_values = sum(sum(Window));\r
50         \r
51         if Number_values < Mv\r
52                 Mode = Initial;\r
53                 Number_values = 0;\r
54                 return;\r
55         end\r
56 \r
57    Next_val = round(Sum_values/Number_values);\r
58 end\r
59 Mode = Next_val;\r
60 \r
61 % text(Next_val(1)+Window_radius/1.8, Next_val(2)+Window_radius/4, 'Final');\r
62 % plot_number = plot_number+1;\r