summaryrefslogtreecommitdiffstats
path: root/SD-VBS/common/toolbox/toolbox_basic/stella/showncut.m
diff options
context:
space:
mode:
Diffstat (limited to 'SD-VBS/common/toolbox/toolbox_basic/stella/showncut.m')
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/stella/showncut.m92
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
13function [g,lgd,v,s,dd] = showncut(fn,rec_num)
14
15globalenvar; cd(IMAGE_DIR);cd(fn); feval([fn,'_par']);cd(HOME_DIR);
16par = p(rec_num);
17no_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
23nr = 5;
24num_plots = nc * nr;
25g = cell(num_plots,1);
26lgd = g;
27names = {'r','\theta','\phi'};
28x = cell(3,1);
29for 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
51end
52
53% fill in slots by image f and affinity pattern
54j = nc + nc; g{j} = getimage2(fn); lgd{j} = sprintf('%d x %d image',m,n);
55j = nr * nc; g{j} = readpcm([fn,'_phase.pfm']); lgd{j} = 'phase';
56j = j - 1; g{j} = exp(-(readpfmc([fn,'_edgecon.pfm'])/(255*par.sig_IC)).^2); lgd{j} = 'IC';
57
58i = round(m*[1;3]./4);
59%i = i([1,1,2,2]);
60j = round(n*[1;3]./4);
61%j = j([1,2,1,2]);
62k = m * (j-1) + i;
63
64a = afromncut(v,s,dd,1,no_rep,k);
65
66y = [4*nc-1, 4*nc, 5*nc-1, 5*nc, 6*nc-1, 6*nc];
67for 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));
70end
71
72% find parameters
73fg_title = sprintf('%s: %s=%d, %s=%d, %s=%3.2f, %s=%3.2f',...
74par.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
80openfigure(nr,nc,fg_title,0);
81dispimg(g,[nr,nc],lgd);
82
83% fix
84subplot(nr,nc,nc*3);
85plot(s,'ro'); title('\lambda');
86axis square; axis tight; set(gca,'XTick',[]);
87for t=1:length(k),
88 subplot(nr,nc,y(t));
89 hold on;
90 text(j(t),i(t),'+');
91end
92hold off