summaryrefslogtreecommitdiffstats
path: root/SD-VBS/common/toolbox/toolbox_basic/stella
diff options
context:
space:
mode:
Diffstat (limited to 'SD-VBS/common/toolbox/toolbox_basic/stella')
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/stella/afromncut.m73
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/stella/dispimg.m65
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/stella/firstncut.m67
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/stella/getfnames.m47
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/stella/getimage2.m46
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/stella/globalenvar.m6
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/stella/jshincut.m94
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/stella/jshincutdefpar.m20
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/stella/ncutcheckin.m136
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/stella/openfigure.m52
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/stella/showim.m36
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/stella/showncut.m92
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/stella/startup.m18
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/stella/test_ncutm.m38
14 files changed, 790 insertions, 0 deletions
diff --git a/SD-VBS/common/toolbox/toolbox_basic/stella/afromncut.m b/SD-VBS/common/toolbox/toolbox_basic/stella/afromncut.m
new file mode 100755
index 0000000..ec014d0
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/stella/afromncut.m
@@ -0,0 +1,73 @@
1% function a = afromncut(v,s,d,visimg,no_rep,pixel_loc)
2% Input:
3% v = eigenvectors of d*a*d, starting from the second.
4% (the first is all one over some constant determined by d)
5% s = eigenvalues
6% d = normalization matrix 1/sqrt(rowsum(abs(a)))
7% visimg = 1/0 if each eigenvector is/not 2D (so v is 3D)
8% no_rep = 1 (default), affinity has attraction only
9% if 1, the first column of v is the second eigenvector
10% if 0, the first column of v is the first eigenvector.
11% pixel_loc = nx1 matrix, each is a pixel location
12% Output:
13% a = diag(1/d) * na * diag(1/d);
14% If pixel_loc = []; a is returned, if not out of memory
15% otherwise, only rows of a at pixel_loc are returned.
16%
17% This routine is used to estimate the original affinity matrix
18% through the first few eigenvectors and its normalization matrix.
19
20% A test sequence includes:
21% a = randsym(5);
22% [na,d] = normalize(a);
23% [v,s] = ncut(a,5);
24% v = v(:,2:end); s = s(2:end);
25% aa = afromncut(v,s,d);
26% max(abs(aa(:) - a(:)))
27
28% Stella X. Yu, 2000.
29
30function a = afromncut(v,s,d,visimg,no_rep,pixel_loc)
31
32[nr,nc,nv] = size(v);
33if nargin<4 | isempty(visimg),
34 visimg = (nv>1);
35end
36
37if nargin<5 | isempty(no_rep),
38 no_rep = 1;
39end
40
41if visimg,
42 nr = nr * nc;
43else
44 nv = nc;
45end
46
47if nargin<6 | isempty(pixel_loc),
48 pixel_loc = 1:nr;
49end
50
51% D^(1/2)
52d = 1./(d(:)+eps);
53
54% first recover the first eigenvector
55if no_rep,
56 u = (1/norm(d)) + zeros(nr,1);
57 s = [1;s(:)];
58 nv = nv + 1;
59else
60 u = [];
61end
62
63% the full set of generalized eigenvectors
64v = [u, reshape(v,[nr,nv-no_rep])];
65
66% This is the real D, row sum
67d = d.^2;
68
69% an equivalent way to compute v = diag(d) * v;
70v = v .* d(:,ones(nv,1)); % to avoid using a big matrix diag(d)
71
72% synthesis
73a = v(pixel_loc,:)*diag(s)*v';
diff --git a/SD-VBS/common/toolbox/toolbox_basic/stella/dispimg.m b/SD-VBS/common/toolbox/toolbox_basic/stella/dispimg.m
new file mode 100755
index 0000000..4e419a0
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/stella/dispimg.m
@@ -0,0 +1,65 @@
1% function dispimg(g,fmt,lgd,cmap) display multiple images in one figure.
2% Input:
3% g = a cell and fmt is a 1x2 vector specifying the layout.
4% lgd = a string cell for the title of each image.
5% cmap = the colormap (default is the gray, -1 for the inverted gray).
6% ishori = a vector of 1/0 to display real and imag parts horizontally / vertically
7
8% Stella X. Yu, 2000.
9
10function dispimg(g,fmt,lgd,cmap,ishori);
11
12cellg = iscell(g);
13if cellg,
14 num_fig = length(g);
15else
16 num_fig = size(g,3);
17end;
18
19if nargin<2 | isempty(fmt),
20 m = ceil(sqrt(num_fig));
21 n = ceil(num_fig / m);
22else
23 m = fmt(1);
24 n = fmt(2);
25end
26
27if nargin<3 | isempty(lgd),
28 lgd = 1:num_fig;
29end
30if isnumeric(lgd),
31 lgd = cellstr(num2str(lgd(:),3));
32end
33i = size(lgd);
34if i(1)==1,
35 lgd = [lgd, cell(1,num_fig-i(2))];
36else
37 lgd = [lgd; cell(num_fig-i(1),1)];
38end
39
40if nargin<5 | isempty(ishori),
41 ishori = ones(num_fig,1);
42end
43ishori(end+1:num_fig) = ishori(end);
44
45for k=1:num_fig,
46 subplot(m,n,k);
47 if cellg,
48 showim(g{k},[],ishori(k));
49 else
50 showim(g(:,:,k),[],ishori(k));
51 end
52 title(lgd{k});
53end
54
55if nargin<4 | isempty(cmap),
56 cmap = gray;
57end
58if length(cmap)==1,
59 if cmap==1,
60 cmap = gray;
61 else
62 cmap = flipud(gray);
63 end
64end
65colormap(cmap);
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
diff --git a/SD-VBS/common/toolbox/toolbox_basic/stella/getfnames.m b/SD-VBS/common/toolbox/toolbox_basic/stella/getfnames.m
new file mode 100755
index 0000000..4990451
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/stella/getfnames.m
@@ -0,0 +1,47 @@
1% function [fn,dn] = getfnames(direc,opt)
2% Input:
3% direc = directory
4% opt = wildcat
5% Output:
6% fn = a cell with all filenames under direc and with opt
7% dn = a cell with all directory names under direc and with opt
8% For example, getfnames('19990910','*.jpg');
9% Set IS_PC according to your platform in globalenvar.m
10
11% Stella X. Yu, 2000.
12
13function [fn,dn] = getfnames(direc,opt)
14
15if (nargin<1 | isempty(direc)),
16 direc = '.';
17end
18
19if nargin<2 | isempty(opt),
20 opt = [];
21end
22
23fn = {};
24dn = {};
25
26cur_dir = pwd;
27cd(direc);
28s = dir(opt);
29if isempty(s),
30 disp('getfnames: no data');
31 return;
32end
33
34n = length(s);
35i = 1;
36j = 1;
37for k=1:n,
38 if s(k).isdir,
39 dn{j,1} = s(k).name;
40 j = j + 1;
41 else
42 fn{i,1} = s(k).name;
43 i = i + 1;
44 end
45end
46 cd(cur_dir)
47%[fn{1:n,1}]=deal(s.name);
diff --git a/SD-VBS/common/toolbox/toolbox_basic/stella/getimage2.m b/SD-VBS/common/toolbox/toolbox_basic/stella/getimage2.m
new file mode 100755
index 0000000..945ddd2
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/stella/getimage2.m
@@ -0,0 +1,46 @@
1% function f = getimage2(imagefile) returns a normalized intensity image.
2% If the file postfix is not given, then I will search any possible image file
3% under the IMAGE_DIR.
4
5% Stella X. Yu, March 1999
6
7function f = getimage2(imagefile)
8
9if exist(imagefile)==2,
10 g = {imagefile};
11else
12 g = {};
13end
14globalenvar;
15g = [g; getfnames(IMAGE_DIR,[imagefile,'.*'])];
16
17j = 1;
18for i=1:length(g),
19 k = findstr(g{i},'.');
20 gp = g{i}(k(end)+1:end);
21 if strcmp(gp,'ppm'),
22 f = double(readppm(g{i}));
23 j = 0;
24 elseif sum(strcmp(gp,{'jpg','tif','jpeg','tiff','bmp','png','hdf','pcx','xwd'}))>0,
25 f = double(imread(g{i}));
26 j = 0;
27 end
28 if j==0,
29 disp(sprintf('This is an image read from %s under %s',g{i},IMAGE_DIR));
30 break;
31 end
32end
33if j,
34 f = [];
35 disp('Image not found');
36 return;
37end
38
39if size(f,3)>1,
40 %f = sum(f,3)./3;
41 f = rgb2ntsc(f);
42 f = f(:,:,1);
43end
44minf = min(f(:));
45maxf = max(f(:));
46f = (f - minf) ./ (maxf - minf);
diff --git a/SD-VBS/common/toolbox/toolbox_basic/stella/globalenvar.m b/SD-VBS/common/toolbox/toolbox_basic/stella/globalenvar.m
new file mode 100755
index 0000000..1e61b61
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/stella/globalenvar.m
@@ -0,0 +1,6 @@
1% globalenvar
2
3HOME_DIR = '/hid/jshi/Research/walking/stella';
4IMAGE_DIR = '/hid/jshi/test_images';
5C_DIR = '/hid/jshi/Research/Ncut_code_C';
6IS_PC = 0;
diff --git a/SD-VBS/common/toolbox/toolbox_basic/stella/jshincut.m b/SD-VBS/common/toolbox/toolbox_basic/stella/jshincut.m
new file mode 100755
index 0000000..d0f11cb
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/stella/jshincut.m
@@ -0,0 +1,94 @@
1% function [par, rec_num] = jshincut(par,image_dir)
2% Input:
3% par = a structure with parameters for command_ncut.tex
4% image_dir = the directory where the imagefile is stored
5% Output:
6% par = parameters used
7% rec_num = record number in the NCut database
8% Jianbo Shi's ncut_IC is applied to the image
9% (If there is no .ppm format for the named image,
10% conversion from related files would be attempted.)
11% Results are organized according to the parameters.
12% Example: jshincut('240018s');
13% See also: jshincutdefpar; ncutcheckin
14% Set IS_PC according to your platform in globalenvar.m
15
16% Stella X. Yu, 2000.
17
18function [par,rec_num] = jshincut(par,image_dir)
19
20rec = jshincutdefpar;
21
22fields = fieldnames(rec);
23nf = length(fields);
24
25if ischar(par),
26 imagename = par;
27 par = rec;
28 par.fname_base = imagename;
29end
30
31globalenvar;
32
33if nargin<2 | isempty(image_dir),
34 image_dir = IMAGE_DIR;
35end
36
37imagename = getfield(par,fields{1});
38for i=2:nf,
39 t = getfield(par,fields{i});
40 if isempty(t),
41 par = setfield(par,fields{i},getfield(rec,fields{i}));
42 end
43end
44
45% dir and filename
46catchar = {'/','\'};
47catchar = catchar{IS_PC+1};
48
49% first check if there is a ppm file for this image
50if not(exist([image_dir,catchar,imagename,'.ppm'])),
51 j = getfnames(image_dir,[imagename,'.*']);
52 if isempty(j),
53 disp('Image not found.');
54 return;
55 end
56 k = 0;
57 for i=1:length(j),
58 k = k + not(isempty(im2ppm(j{i},image_dir)));
59 if k==1,
60 disp(sprintf('%s -> %s.ppm succeeded.',j{i},imagename));
61 break;
62 end
63 end
64 if k==0,
65 disp('Sorry. Attempt to convert your named image into ppm format failed.');
66 return;
67 end
68end
69
70cd(C_DIR);
71
72% generate command_ncut.tex file
73fn = 'command_ncut.tex';
74fid = fopen(fn,'w');
75fprintf(fid,'%21s\t%s%c%s\n',fields{1},image_dir,catchar,imagename);
76for i=2:nf,
77 t = getfield(par,fields{i});
78 if isnumeric(t),
79 t = num2str(t);
80 end
81 fprintf(fid,['%21s\t%s\n'],fields{i},t);
82end
83fclose(fid);
84%disp('You can check and modify command_ncut.tex before I run ncut_IC on it. Good?');pause(1);
85
86% run ncut_IC
87unix(['.',catchar,'ncut_IC']);
88cd(HOME_DIR);
89
90% check in
91copyfile([C_DIR,catchar,fn],[image_dir,catchar,fn]);
92rec_num = ncutcheckin(fn,image_dir,image_dir);
93%delete([image_dir,catchar,imagename,'.ppm']);
94%delete([image_dir,catchar,fn]);
diff --git a/SD-VBS/common/toolbox/toolbox_basic/stella/jshincutdefpar.m b/SD-VBS/common/toolbox/toolbox_basic/stella/jshincutdefpar.m
new file mode 100755
index 0000000..4f07192
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/stella/jshincutdefpar.m
@@ -0,0 +1,20 @@
1% function rec = jshincutdefpar;
2% default parameter setting for Jianbo Shi's NCut C codes
3
4% Stella X. Yu, 2000.
5
6function rec = jshincutdefpar;
7
8rec.fname_base = '240018s';
9rec.fname_ext = 'ppm';
10rec.num_eigvecs = 15;
11rec.spatial_neighborhood_x=20;
12rec.sigma_x= 10;
13rec.sig_I= -0.16;
14rec.sig_IC= 0.01;
15rec.hr= 2;
16rec.eig_blk_sze= 3;
17rec.power_D= 1;
18rec.offset = 0.0;
19rec.sig_filter = 1.0;
20rec.elong_filter = 3.0;
diff --git a/SD-VBS/common/toolbox/toolbox_basic/stella/ncutcheckin.m b/SD-VBS/common/toolbox/toolbox_basic/stella/ncutcheckin.m
new file mode 100755
index 0000000..cd82ee5
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/stella/ncutcheckin.m
@@ -0,0 +1,136 @@
1% function rec_num = ncutcheckin(fn,sdir,tdir)
2% Input:
3% fn = parameter file name, default = 'command_ncut.tex'
4% sdir = source dir for fn as well as data files
5% tdir = target dir to check in, both default = IMAGE_DIR
6% Output:
7% rec_num = the number of current parameter records
8% The imagefile_par.m is updated if fn contains a new
9% parameter set. Data files are tagged and copied over to
10% a subdir under tdir.
11% Example: ncutcheckin;
12% Set IS_PC, IMAGE_DIR according to your platform in globalenvar.m
13
14% Stella X. Yu, 2000.
15
16function rec_num = ncutcheckin(fn,sdir,tdir)
17
18globalenvar;
19
20cur_dir = pwd;
21
22if nargin<1 | isempty(fn),
23 fn = 'command_ncut.tex';
24end
25
26if nargin<2 | isempty(sdir),
27 sdir = IMAGE_DIR;
28end
29
30if nargin<3 | isempty(tdir),
31 tdir = IMAGE_DIR;
32end
33
34rec = jshincutdefpar;
35
36% first, generate a parameter record from fn
37cd(sdir);
38[names,values] = textread(fn,'%s %s','commentstyle','shell');
39n = length(names);
40s = rec;
41for i=1:n,
42 j = str2num(values{i});
43 if isempty(j),
44 s = setfield(s,names{i},values{i});
45 else
46 s = setfield(s,names{i},j);
47 end
48end
49cd(cur_dir);
50
51% special care to extract the image file name
52imagename = getfield(s,names{1});
53catchar = {'/','\'};
54catchar = catchar{IS_PC + 1};
55k = max([0,findstr(imagename,catchar)]);
56imagename = imagename(k+1:end);
57s = setfield(s,names{1},imagename);
58
59% second, check if the target dir contains a profile for the image
60cd(tdir);
61if not(exist(imagename,'dir')),
62 mkdir(imagename);
63 cd(cur_dir);
64 j = [catchar,imagename,'.',getfield(s,names{2})];
65 copyfile([sdir,j],[tdir,catchar,imagename,j]);
66 cd(tdir);
67end
68cd(imagename);
69j = [imagename,'_par'];
70if not(exist(j)),
71 rec_num = 1;
72 p = s;
73else
74 % load par file
75 feval(j);
76 rec_num = length(p);
77 i = 1;
78 while (i<=rec_num),
79 k = 0;
80 for j=1:n,
81 k = k + sum(getfield(s,names{j})-getfield(p(i),names{j}));
82 end
83 if k==0,
84 if not(isempty(input(['Data already existed as record # ',num2str(i),...
85 '\nPress any non-return key to Overwrite'],'s'))),
86 break;
87 else
88 rec_num = i; % have checked in already, no update
89 cd(cur_dir);
90 return;
91 end
92 else
93 i = i + 1;
94 end
95 end
96 rec_num = i; % new parameter setting
97 p(rec_num)=s;
98end
99tdir = [tdir,catchar,imagename];
100cd(cur_dir);
101
102% third, check in data files
103% leave .ppm and _edgecon, _phase files
104% if not(exist([tdir,catchar,imagename,'.ppm'])),
105% copyfile([sdir,catchar,imagename,'.ppm'],[tdir,catchar,imagename,'.ppm']);
106% end
107
108% IC files only
109dn = getfnames(sdir,[imagename,'*_IC*.*']);
110header = sprintf('%s%c%s_%d_',tdir,catchar,imagename,rec_num);
111j = length(imagename)+2;
112k = length(dn);
113for i=1:k,
114 copyfile([sdir,catchar,dn{i}],[header,dn{i}(j:end)]);
115 delete([sdir,catchar,dn{i}]);
116end
117disp(sprintf('%d files checked in as record #%d',k,rec_num));
118
119
120% finally, update parameter file
121cd(tdir);
122fid = fopen([imagename,'_par.m'],'w');
123fprintf(fid,'%% Last checked in at %s\n\n',datestr(now));
124for i=1:rec_num,
125 for j=1:n,
126 k = getfield(p(i),names{j});
127 if ischar(k),
128 fprintf(fid,'p(%d).%s=\''%s\'';\n',i,names{j},k);
129 else
130 fprintf(fid,'p(%d).%s=%s;\n',i,names{j},num2str(k));
131 end
132 end
133 fprintf(fid,'\n');
134end
135fclose(fid);
136cd(cur_dir); \ No newline at end of file
diff --git a/SD-VBS/common/toolbox/toolbox_basic/stella/openfigure.m b/SD-VBS/common/toolbox/toolbox_basic/stella/openfigure.m
new file mode 100755
index 0000000..e677014
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/stella/openfigure.m
@@ -0,0 +1,52 @@
1% function openfigure(m,n,caption,isnew)
2function h = openfigure(m,n,caption,isnew)
3
4if nargin<3,
5 caption = ' ';
6end
7
8if nargin<4,
9 isnew = 1;
10end
11
12if (m<=0 | n<=0)
13 return;
14end
15
16if isnew,
17 h = figure; colormap(gray);
18else
19 h = gcf;
20end
21clf
22
23subplot('position',[0,0,0.1,0.1]); axis off;
24text(0.1,0.15,sprintf('S. X. Yu, %s',date),'FontSize',8);
25
26subplot('position',[0,0.96,0.1,0.1]); axis off;
27text(0.1,0.15,caption,'FontSize',8);
28
29subplot(m,n,1);
30%return
31
32if (m==1 & n==1),
33 return;
34end
35
36%set(gcf,'PaperPosition',[0.25, 8, 8,2.5*m]);
37% set(gcf,'PaperPosition',[0.25,0.25,8,10.5]);
38%return
39
40if (m<=n),
41 set(gcf,'PaperOrientation','landscape','PaperPosition',[0.25,0.25,10.5,8]);
42else
43 set(gcf,'PaperPosition',[0.25,0.25,8,10.5]);
44end
45
46% comment on PaperPosition
47% [a,b,c,d]
48% (a,b) is the coordinate of the lower-left corner of the figure
49% (a,b) = (0,0) is the lower-left corner of the paper
50% (c,d) is the coordinate of the upper-right corner of the figure relative to the lower-left corner of the figure
51% Therefore, c>=a, d>=b
52% Full paper position would be [0,0,8.5,11] in inches
diff --git a/SD-VBS/common/toolbox/toolbox_basic/stella/showim.m b/SD-VBS/common/toolbox/toolbox_basic/stella/showim.m
new file mode 100755
index 0000000..10db297
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/stella/showim.m
@@ -0,0 +1,36 @@
1% function showim(f,cmap) display real or complex image.
2% When it is complex, the real part and imaginary part
3% are displayed as [real,imag] in one image.
4% cmap is the colormap. default = gray, -1 = inverted gray.
5
6% Stella X. Yu, 2000.
7
8function showim(f,cmap,ishori)
9
10if not(isreal(f)),
11 i = [real(f(:)); imag(f(:))];
12 j = [min(i), max(i)];
13 [nr,nc] = size(f);
14 if nargin<3 | isempty(ishori),
15 ishori = nr>nc;
16 end
17 if ishori,
18 i = zeros(nr,1);
19 f = [real(f), [i+j(1),i+j(2)], imag(f)];
20 else
21 i = zeros(1,nc);
22 f = [real(f); [i+j(1);i+j(2)]; imag(f)];
23 end
24end
25imagesc(f); axis off; axis image;
26
27if nargin<2 | isempty(cmap),
28 return;
29end
30
31if cmap==1,
32 cmap = gray;
33elseif cmap==-1,
34 cmap = flipud(gray);
35end
36colormap(cmap); \ No newline at end of file
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
diff --git a/SD-VBS/common/toolbox/toolbox_basic/stella/startup.m b/SD-VBS/common/toolbox/toolbox_basic/stella/startup.m
new file mode 100755
index 0000000..262429a
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/stella/startup.m
@@ -0,0 +1,18 @@
1globalenvar;
2
3addpath(IMAGE_DIR);
4
5addpath(HOME_DIR);
6
7path(path,['/hid/jshi/Research/walking']);
8
9tb_dir = ['/hid/jshi/matlab/toolbox/'];
10
11path(path,[tb_dir,'io']);
12path(path,[tb_dir,'filter']);
13path(path,[tb_dir,'filter_hist']);
14path(path,[tb_dir,'disp']);
15path(path,[tb_dir,'common']);
16path(path,[tb_dir,'textons']);
17path(path,[tb_dir,'pyramid']);
18
diff --git a/SD-VBS/common/toolbox/toolbox_basic/stella/test_ncutm.m b/SD-VBS/common/toolbox/toolbox_basic/stella/test_ncutm.m
new file mode 100755
index 0000000..c9b46ab
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/stella/test_ncutm.m
@@ -0,0 +1,38 @@
1fn = 'walk1';
2
3repulsion_test = 1;
4
5if 1,
6 f = getimage2(fn);
7 par = jshincutdefpar;
8 par.fname_base = fn;
9 par.spatial_neighborhood_x = 10;
10 par.sigma_x = 3 * par.spatial_neighborhood_x;
11 par.sig_IC = 0.03;
12 par.num_eigvecs = 10;
13 par.offset = 0.00;
14 par.sig_filter = 1.0;
15 par.elong_filter = 3.0;
16 [par,rec_num] = jshincut(par);
17 [g,lgd,v,s,dd] = showncut(fn,rec_num);
18
19if repulsion_test,
20 par.offset = 0.1;
21 [par,rec_num] = jshincut(par);
22 figure;
23 [g,lgd,v,s,dd] = showncut(fn,rec_num);
24end
25end
26
27if 0,
28 x = v(:,:,1);
29 y = v(:,:,2);
30 figure;
31 subplot(2,1,1); plot(x(:),y(:),'ro');
32 r = sqrt(x.^2+y.^2);
33 x = x./r;
34 y = y./r;
35 subplot(2,1,2); im([x,y]*[x,y]');
36 % mask = (x>0) & y>0;
37 % showmask(f,mask);
38end