summaryrefslogtreecommitdiffstats
path: root/SD-VBS/common/toolbox/toolbox_basic/stella
diff options
context:
space:
mode:
authorleochanj105 <leochanj@live.unc.edu>2020-10-19 23:09:30 -0400
committerleochanj105 <leochanj@live.unc.edu>2020-10-20 02:40:39 -0400
commitf618466c25d43f3bae9e40920273bf77de1e1149 (patch)
tree460e739e2165b8a9c37a9c7ab1b60f5874903543 /SD-VBS/common/toolbox/toolbox_basic/stella
parent47ced4e96bbb782b9e780e8f2cfc637b2c21ff44 (diff)
initial sd-vbs
initial sd-vbs add sd-vbs sd-vbs
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,