diff options
Diffstat (limited to 'SD-VBS/common/toolbox/toolbox_basic/stella/showncut.m')
-rwxr-xr-x | SD-VBS/common/toolbox/toolbox_basic/stella/showncut.m | 92 |
1 files changed, 92 insertions, 0 deletions
diff --git a/SD-VBS/common/toolbox/toolbox_basic/stella/showncut.m b/SD-VBS/common/toolbox/toolbox_basic/stella/showncut.m new file mode 100755 index 0000000..b1fe1f4 --- /dev/null +++ b/SD-VBS/common/toolbox/toolbox_basic/stella/showncut.m | |||
@@ -0,0 +1,92 @@ | |||
1 | % function [g,lgd,v,s,dd] = showncut(fn,rec_num) | ||
2 | % Input: | ||
3 | % fn = file / image name | ||
4 | % rec_num = Ncut record number | ||
5 | % Output: | ||
6 | % g = a cell contains 1D, 2D and 3D embeddings | ||
7 | % lgd = legend for g | ||
8 | % v = eigenvectors | ||
9 | % s = eigenvalues | ||
10 | % dd = normalization matrix = 1/sqrt(rowsum(abs(a))) | ||
11 | % an image is displayed | ||
12 | |||
13 | function [g,lgd,v,s,dd] = showncut(fn,rec_num) | ||
14 | |||
15 | globalenvar; cd(IMAGE_DIR);cd(fn); feval([fn,'_par']);cd(HOME_DIR); | ||
16 | par = p(rec_num); | ||
17 | no_rep = (par.offset<1e-6); | ||
18 | |||
19 | [v,s,dd] = firstncut(fn,rec_num); | ||
20 | [m,n,nc] = size(v); | ||
21 | |||
22 | % generate images for display | ||
23 | nr = 5; | ||
24 | num_plots = nc * nr; | ||
25 | g = cell(num_plots,1); | ||
26 | lgd = g; | ||
27 | names = {'r','\theta','\phi'}; | ||
28 | x = cell(3,1); | ||
29 | for j=1:nc, | ||
30 | g{j} = v(:,:,j); | ||
31 | lgd{j} = sprintf('%s_{%d} = %1.2f','\lambda', j+no_rep, s(j)); | ||
32 | |||
33 | if j<nc, | ||
34 | [x{2},x{1}] = cart2pol(v(:,:,j),v(:,:,j+1)); | ||
35 | k = j; | ||
36 | for t=1:2, | ||
37 | k = k + nc; | ||
38 | g{k} = x{t}; | ||
39 | lgd{k} = sprintf('%s_{%d,%d}',names{t},j+[0:1]+no_rep); | ||
40 | end | ||
41 | |||
42 | if j<nc-1, | ||
43 | [x{2},x{3},x{1}] = cart2sph(v(:,:,j),v(:,:,j+1),v(:,:,j+2)); | ||
44 | for t=[1,3], % theta must be the same as 2D embedding, so ignore it | ||
45 | k = k + nc; | ||
46 | g{k} = x{t}; | ||
47 | lgd{k} = sprintf('%s_{%d,%d,%d}',names{t},j+[0:2]+no_rep); | ||
48 | end | ||
49 | end | ||
50 | end | ||
51 | end | ||
52 | |||
53 | % fill in slots by image f and affinity pattern | ||
54 | j = nc + nc; g{j} = getimage2(fn); lgd{j} = sprintf('%d x %d image',m,n); | ||
55 | j = nr * nc; g{j} = readpcm([fn,'_phase.pfm']); lgd{j} = 'phase'; | ||
56 | j = j - 1; g{j} = exp(-(readpfmc([fn,'_edgecon.pfm'])/(255*par.sig_IC)).^2); lgd{j} = 'IC'; | ||
57 | |||
58 | i = round(m*[1;3]./4); | ||
59 | %i = i([1,1,2,2]); | ||
60 | j = round(n*[1;3]./4); | ||
61 | %j = j([1,2,1,2]); | ||
62 | k = m * (j-1) + i; | ||
63 | |||
64 | a = afromncut(v,s,dd,1,no_rep,k); | ||
65 | |||
66 | y = [4*nc-1, 4*nc, 5*nc-1, 5*nc, 6*nc-1, 6*nc]; | ||
67 | for t=1:length(k), | ||
68 | g{y(t)} = reshape(a(t,:),[m,n]); | ||
69 | lgd{y(t)} = sprintf('a at (%d,%d)',i(t),j(t)); | ||
70 | end | ||
71 | |||
72 | % find parameters | ||
73 | fg_title = sprintf('%s: %s=%d, %s=%d, %s=%3.2f, %s=%3.2f',... | ||
74 | par.fname_base,... | ||
75 | 'r_x', par.spatial_neighborhood_x,... | ||
76 | '\sigma_x',par.sigma_x,... | ||
77 | '\sigma_{IC}',par.sig_IC,... | ||
78 | 'repulsion',par.offset); | ||
79 | |||
80 | openfigure(nr,nc,fg_title,0); | ||
81 | dispimg(g,[nr,nc],lgd); | ||
82 | |||
83 | % fix | ||
84 | subplot(nr,nc,nc*3); | ||
85 | plot(s,'ro'); title('\lambda'); | ||
86 | axis square; axis tight; set(gca,'XTick',[]); | ||
87 | for t=1:length(k), | ||
88 | subplot(nr,nc,y(t)); | ||
89 | hold on; | ||
90 | text(j(t),i(t),'+'); | ||
91 | end | ||
92 | hold off | ||