summaryrefslogtreecommitdiffstats
path: root/SD-VBS/common/toolbox/toolbox_basic/stella/firstncut.m
diff options
context:
space:
mode:
Diffstat (limited to 'SD-VBS/common/toolbox/toolbox_basic/stella/firstncut.m')
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/stella/firstncut.m67
1 files changed, 67 insertions, 0 deletions
diff --git a/SD-VBS/common/toolbox/toolbox_basic/stella/firstncut.m b/SD-VBS/common/toolbox/toolbox_basic/stella/firstncut.m
new file mode 100755
index 0000000..a22077d
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/stella/firstncut.m
@@ -0,0 +1,67 @@
1% function [v,s,d] = firstncut(base_name,rec_num)
2% Input:
3% base_name = image name
4% rec_num = parameter record number
5% Output:
6% v = eigenvectors
7% s = eigenvalues
8% d = normalization matrix d = 1/sqrt(rowsum(abs(a)))
9% Convert Jianbo Shi's Ncut Ccode results from images to matlab matrices.
10
11% Stella X. Yu, 2000.
12
13function [v,s,d] = firstncut(base_name,rec_num);
14
15if nargin<2 | isempty(rec_num),
16 rec_num = 1;
17end
18
19cur_dir = pwd;
20globalenvar;
21cd(IMAGE_DIR);
22cd(base_name);
23 feval([base_name,'_par']);
24 j = length(p);
25 if rec_num>j,
26 disp(sprintf('parameter record number %d out of range %d, check %s!',rec_num,j,[base_name,'_par.m']));
27 Qlabel = [];
28 v = [];
29 s = [];
30 ev_info = [];
31 return;
32 end
33 nv = p(rec_num).num_eigvecs;
34 no_rep = (p(rec_num).offset<1e-6);
35
36 % read the image
37 cm=sprintf('I = readppm(''%s.ppm'');',base_name);
38 eval(cm);
39
40 % read eigenvectors
41 base_name_hist = sprintf('%s_%d_IC',base_name,rec_num);
42 if no_rep,
43 [v,ev_info] = read_ev_pgm(base_name_hist,1,1,nv);
44 else
45 [v,ev_info] = read_ev_pgm2(base_name_hist,1,1,nv);
46 end
47 s = ev_info(4,:)';
48
49 % read the normalization matrix
50 d = readpfmc(sprintf('%s_%d_D_IC.pfm',base_name,rec_num));
51cd(cur_dir);
52
53% D^(1/2)
54dd = (1./(d(:)+eps));
55
56% recover real eigenvectors
57for j = 1:nv-no_rep,
58 vmin = ev_info(1,j);
59 vmax = ev_info(2,j);
60 y = v(:,:,j).*((vmax - vmin)/256) + vmin;
61 %validity check: x = D^(1/2)y should be normalized
62 x = norm(y(:).*dd);
63 v(:,:,j) = y./x;
64end
65
66dispimg(cat(3,mean(I,3),v),[],[{'image'};cellstr(num2str(s,3))]);
67