summaryrefslogtreecommitdiffstats
path: root/SD-VBS/common/toolbox/toolbox_basic/stella/afromncut.m
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/afromncut.m
parent47ced4e96bbb782b9e780e8f2cfc637b2c21ff44 (diff)
initial sd-vbs
initial sd-vbs add sd-vbs sd-vbs
Diffstat (limited to 'SD-VBS/common/toolbox/toolbox_basic/stella/afromncut.m')
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/stella/afromncut.m73
1 files changed, 73 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';