diff options
| author | leochanj105 <leochanj@live.unc.edu> | 2020-10-19 23:09:30 -0400 |
|---|---|---|
| committer | leochanj105 <leochanj@live.unc.edu> | 2020-10-20 02:40:39 -0400 |
| commit | f618466c25d43f3bae9e40920273bf77de1e1149 (patch) | |
| tree | 460e739e2165b8a9c37a9c7ab1b60f5874903543 /SD-VBS/common/toolbox/toolbox_basic/stella | |
| parent | 47ced4e96bbb782b9e780e8f2cfc637b2c21ff44 (diff) | |
initial sd-vbs
initial sd-vbs
add sd-vbs
sd-vbs
Diffstat (limited to 'SD-VBS/common/toolbox/toolbox_basic/stella')
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 | |||
| 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'; | ||
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 | |||
| 10 | function dispimg(g,fmt,lgd,cmap,ishori); | ||
| 11 | |||
| 12 | cellg = iscell(g); | ||
| 13 | if cellg, | ||
| 14 | num_fig = length(g); | ||
| 15 | else | ||
| 16 | num_fig = size(g,3); | ||
| 17 | end; | ||
| 18 | |||
| 19 | if nargin<2 | isempty(fmt), | ||
| 20 | m = ceil(sqrt(num_fig)); | ||
| 21 | n = ceil(num_fig / m); | ||
| 22 | else | ||
| 23 | m = fmt(1); | ||
| 24 | n = fmt(2); | ||
| 25 | end | ||
| 26 | |||
| 27 | if nargin<3 | isempty(lgd), | ||
| 28 | lgd = 1:num_fig; | ||
| 29 | end | ||
| 30 | if isnumeric(lgd), | ||
| 31 | lgd = cellstr(num2str(lgd(:),3)); | ||
| 32 | end | ||
| 33 | i = size(lgd); | ||
| 34 | if i(1)==1, | ||
| 35 | lgd = [lgd, cell(1,num_fig-i(2))]; | ||
| 36 | else | ||
| 37 | lgd = [lgd; cell(num_fig-i(1),1)]; | ||
| 38 | end | ||
| 39 | |||
| 40 | if nargin<5 | isempty(ishori), | ||
| 41 | ishori = ones(num_fig,1); | ||
| 42 | end | ||
| 43 | ishori(end+1:num_fig) = ishori(end); | ||
| 44 | |||
| 45 | for 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}); | ||
| 53 | end | ||
| 54 | |||
| 55 | if nargin<4 | isempty(cmap), | ||
| 56 | cmap = gray; | ||
| 57 | end | ||
| 58 | if length(cmap)==1, | ||
| 59 | if cmap==1, | ||
| 60 | cmap = gray; | ||
| 61 | else | ||
| 62 | cmap = flipud(gray); | ||
| 63 | end | ||
| 64 | end | ||
| 65 | colormap(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 | |||
| 13 | function [v,s,d] = firstncut(base_name,rec_num); | ||
| 14 | |||
| 15 | if nargin<2 | isempty(rec_num), | ||
| 16 | rec_num = 1; | ||
| 17 | end | ||
| 18 | |||
| 19 | cur_dir = pwd; | ||
| 20 | globalenvar; | ||
| 21 | cd(IMAGE_DIR); | ||
| 22 | cd(base_name); | ||
| 23 | feval([base_name,'_par']); | ||
| 24 | j = length(p); | ||
| 25 | if rec_num>j, | ||
