diff options
| author | Leo Chan <leochanj@live.unc.edu> | 2020-10-22 01:53:21 -0400 |
|---|---|---|
| committer | Joshua Bakita <jbakita@cs.unc.edu> | 2020-10-22 01:56:35 -0400 |
| commit | d17b33131c14864bd1eae275f49a3f148e21cf29 (patch) | |
| tree | 0d8f77922e8d193cb0f6edab83018f057aad64a0 /SD-VBS/common/toolbox/toolbox_basic/stella/afromncut.m | |
| parent | 601ed25a4c5b66cb75315832c15613a727db2c26 (diff) | |
Squashed commit of the sb-vbs branch.
Includes the SD-VBS benchmarks modified to:
- Use libextra to loop as realtime jobs
- Preallocate memory before starting their main computation
- Accept input via stdin instead of via argc
Does not include the SD-VBS matlab code.
Fixes libextra execution in LITMUS^RT.
Diffstat (limited to 'SD-VBS/common/toolbox/toolbox_basic/stella/afromncut.m')
| -rwxr-xr-x | SD-VBS/common/toolbox/toolbox_basic/stella/afromncut.m | 73 |
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 | |||
| 30 | function a = afromncut(v,s,d,visimg,no_rep,pixel_loc) | ||
| 31 | |||
| 32 | [nr,nc,nv] = size(v); | ||
| 33 | if nargin<4 | isempty(visimg), | ||
| 34 | visimg = (nv>1); | ||
| 35 | end | ||
| 36 | |||
| 37 | if nargin<5 | isempty(no_rep), | ||
| 38 | no_rep = 1; | ||
| 39 | end | ||
| 40 | |||
| 41 | if visimg, | ||
| 42 | nr = nr * nc; | ||
| 43 | else | ||
| 44 | nv = nc; | ||
| 45 | end | ||
| 46 | |||
| 47 | if nargin<6 | isempty(pixel_loc), | ||
| 48 | pixel_loc = 1:nr; | ||
| 49 | end | ||
| 50 | |||
| 51 | % D^(1/2) | ||
| 52 | d = 1./(d(:)+eps); | ||
| 53 | |||
| 54 | % first recover the first eigenvector | ||
| 55 | if no_rep, | ||
| 56 | u = (1/norm(d)) + zeros(nr,1); | ||
| 57 | s = [1;s(:)]; | ||
| 58 | nv = nv + 1; | ||
| 59 | else | ||
| 60 | u = []; | ||
| 61 | end | ||
| 62 | |||
| 63 | % the full set of generalized eigenvectors | ||
| 64 | v = [u, reshape(v,[nr,nv-no_rep])]; | ||
| 65 | |||
| 66 | % This is the real D, row sum | ||
| 67 | d = d.^2; | ||
| 68 | |||
| 69 | % an equivalent way to compute v = diag(d) * v; | ||
| 70 | v = v .* d(:,ones(nv,1)); % to avoid using a big matrix diag(d) | ||
| 71 | |||
| 72 | % synthesis | ||
| 73 | a = v(pixel_loc,:)*diag(s)*v'; | ||
