From f618466c25d43f3bae9e40920273bf77de1e1149 Mon Sep 17 00:00:00 2001 From: leochanj105 Date: Mon, 19 Oct 2020 23:09:30 -0400 Subject: initial sd-vbs initial sd-vbs add sd-vbs sd-vbs --- .../toolbox/toolbox_basic/stella/afromncut.m | 73 +++++++++++ .../common/toolbox/toolbox_basic/stella/dispimg.m | 65 ++++++++++ .../toolbox/toolbox_basic/stella/firstncut.m | 67 ++++++++++ .../toolbox/toolbox_basic/stella/getfnames.m | 47 +++++++ .../toolbox/toolbox_basic/stella/getimage2.m | 46 +++++++ .../toolbox/toolbox_basic/stella/globalenvar.m | 6 + .../common/toolbox/toolbox_basic/stella/jshincut.m | 94 ++++++++++++++ .../toolbox/toolbox_basic/stella/jshincutdefpar.m | 20 +++ .../toolbox/toolbox_basic/stella/ncutcheckin.m | 136 +++++++++++++++++++++ .../toolbox/toolbox_basic/stella/openfigure.m | 52 ++++++++ .../common/toolbox/toolbox_basic/stella/showim.m | 36 ++++++ .../common/toolbox/toolbox_basic/stella/showncut.m | 92 ++++++++++++++ .../common/toolbox/toolbox_basic/stella/startup.m | 18 +++ .../toolbox/toolbox_basic/stella/test_ncutm.m | 38 ++++++ 14 files changed, 790 insertions(+) create mode 100755 SD-VBS/common/toolbox/toolbox_basic/stella/afromncut.m create mode 100755 SD-VBS/common/toolbox/toolbox_basic/stella/dispimg.m create mode 100755 SD-VBS/common/toolbox/toolbox_basic/stella/firstncut.m create mode 100755 SD-VBS/common/toolbox/toolbox_basic/stella/getfnames.m create mode 100755 SD-VBS/common/toolbox/toolbox_basic/stella/getimage2.m create mode 100755 SD-VBS/common/toolbox/toolbox_basic/stella/globalenvar.m create mode 100755 SD-VBS/common/toolbox/toolbox_basic/stella/jshincut.m create mode 100755 SD-VBS/common/toolbox/toolbox_basic/stella/jshincutdefpar.m create mode 100755 SD-VBS/common/toolbox/toolbox_basic/stella/ncutcheckin.m create mode 100755 SD-VBS/common/toolbox/toolbox_basic/stella/openfigure.m create mode 100755 SD-VBS/common/toolbox/toolbox_basic/stella/showim.m create mode 100755 SD-VBS/common/toolbox/toolbox_basic/stella/showncut.m create mode 100755 SD-VBS/common/toolbox/toolbox_basic/stella/startup.m create mode 100755 SD-VBS/common/toolbox/toolbox_basic/stella/test_ncutm.m (limited to 'SD-VBS/common/toolbox/toolbox_basic/stella') 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 @@ +% function a = afromncut(v,s,d,visimg,no_rep,pixel_loc) +% Input: +% v = eigenvectors of d*a*d, starting from the second. +% (the first is all one over some constant determined by d) +% s = eigenvalues +% d = normalization matrix 1/sqrt(rowsum(abs(a))) +% visimg = 1/0 if each eigenvector is/not 2D (so v is 3D) +% no_rep = 1 (default), affinity has attraction only +% if 1, the first column of v is the second eigenvector +% if 0, the first column of v is the first eigenvector. +% pixel_loc = nx1 matrix, each is a pixel location +% Output: +% a = diag(1/d) * na * diag(1/d); +% If pixel_loc = []; a is returned, if not out of memory +% otherwise, only rows of a at pixel_loc are returned. +% +% This routine is used to estimate the original affinity matrix +% through the first few eigenvectors and its normalization matrix. + +% A test sequence includes: +% a = randsym(5); +% [na,d] = normalize(a); +% [v,s] = ncut(a,5); +% v = v(:,2:end); s = s(2:end); +% aa = afromncut(v,s,d); +% max(abs(aa(:) - a(:))) + +% Stella X. Yu, 2000. + +function a = afromncut(v,s,d,visimg,no_rep,pixel_loc) + +[nr,nc,nv] = size(v); +if nargin<4 | isempty(visimg), + visimg = (nv>1); +end + +if nargin<5 | isempty(no_rep), + no_rep = 1; +end + +if visimg, + nr = nr * nc; +else + nv = nc; +end + +if nargin<6 | isempty(pixel_loc), + pixel_loc = 1:nr; +end + +% D^(1/2) +d = 1./(d(:)+eps); + +% first recover the first eigenvector +if no_rep, + u = (1/norm(d)) + zeros(nr,1); + s = [1;s(:)]; + nv = nv + 1; +else + u = []; +end + +% the full set of generalized eigenvectors +v = [u, reshape(v,[nr,nv-no_rep])]; + +% This is the real D, row sum +d = d.^2; + +% an equivalent way to compute v = diag(d) * v; +v = v .* d(:,ones(nv,1)); % to avoid using a big matrix diag(d) + +% synthesis +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 @@ +% function dispimg(g,fmt,lgd,cmap) display multiple images in one figure. +% Input: +% g = a cell and fmt is a 1x2 vector specifying the layout. +% lgd = a string cell for the title of each image. +% cmap = the colormap (default is the gray, -1 for the inverted gray). +% ishori = a vector of 1/0 to display real and imag parts horizontally / vertically + +% Stella X. Yu, 2000. + +function dispimg(g,fmt,lgd,cmap,ishori); + +cellg = iscell(g); +if cellg, + num_fig = length(g); +else + num_fig = size(g,3); +end; + +if nargin<2 | isempty(fmt), + m = ceil(sqrt(num_fig)); + n = ceil(num_fig / m); +else + m = fmt(1); + n = fmt(2); +end + +if nargin<3 | isempty(lgd), + lgd = 1:num_fig; +end +if isnumeric(lgd), + lgd = cellstr(num2str(lgd(:),3)); +end +i = size(lgd); +if i(1)==1, + lgd = [lgd, cell(1,num_fig-i(2))]; +else + lgd = [lgd; cell(num_fig-i(1),1)]; +end + +if nargin<5 | isempty(ishori), + ishori = ones(num_fig,1); +end +ishori(end+1:num_fig) = ishori(end); + +for k=1:num_fig, + subplot(m,n,k); + if cellg, + showim(g{k},[],ishori(k)); + else + showim(g(:,:,k),[],ishori(k)); + end + title(lgd{k}); +end + +if nargin<4 | isempty(cmap), + cmap = gray; +end +if length(cmap)==1, + if cmap==1, + cmap = gray; + else + cmap = flipud(gray); + end +end +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 @@ +% function [v,s,d] = firstncut(base_name,rec_num) +% Input: +% base_name = image name +% rec_num = parameter record number +% Output: +% v = eigenvectors +% s = eigenvalues +% d = normalization matrix d = 1/sqrt(rowsum(abs(a))) +% Convert Jianbo Shi's Ncut Ccode results from images to matlab matrices. + +% Stella X. Yu, 2000. + +function [v,s,d] = firstncut(base_name,rec_num); + +if nargin<2 | isempty(rec_num), + rec_num = 1; +end + +cur_dir = pwd; +globalenvar; +cd(IMAGE_DIR); +cd(base_name); + feval([base_name,'_par']); + j = length(p); + if rec_num>j, + disp(sprintf('parameter record number %d out of range %d, check %s!',rec_num,j,[base_name,'_par.m'])); + Qlabel = []; + v = []; + s = []; + ev_info = []; + return; + end + nv = p(rec_num).num_eigvecs; + no_rep = (p(rec_num).offset<1e-6); + + % read the image + cm=sprintf('I = readppm(''%s.ppm'');',base_name); + eval(cm); + + % read eigenvectors + base_name_hist = sprintf('%s_%d_IC',base_name,rec_num); + if no_rep, + [v,ev_info] = read_ev_pgm(base_name_hist,1,1,nv); + else + [v,ev_info] = read_ev_pgm2(base_name_hist,1,1,nv); + end + s = ev_info(4,:)'; + + % read the normalization matrix + d = readpfmc(sprintf('%s_%d_D_IC.pfm',base_name,rec_num)); +cd(cur_dir); + +% D^(1/2) +dd = (1./(d(:)+eps)); + +% recover real eigenvectors +for j = 1:nv-no_rep, + vmin = ev_info(1,j); + vmax = ev_info(2,j); + y = v(:,:,j).*((vmax - vmin)/256) + vmin; + %validity check: x = D^(1/2)y should be normalized + x = norm(y(:).*dd); + v(:,:,j) = y./x; +end + +dispimg(cat(3,mean(I,3),v),[],[{'image'};cellstr(num2str(s,3))]); + 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 @@ +% function [fn,dn] = getfnames(direc,opt) +% Input: +% direc = directory +% opt = wildcat +% Output: +% fn = a cell with all filenames under direc and with opt +% dn = a cell with all directory names under direc and with opt +% For example, getfnames('19990910','*.jpg'); +% Set IS_PC according to your platform in globalenvar.m + +% Stella X. Yu, 2000. + +function [fn,dn] = getfnames(direc,opt) + +if (nargin<1 | isempty(direc)), + direc = '.'; +end + +if nargin<2 | isempty(opt), + opt = []; +end + +fn = {}; +dn = {}; + +cur_dir = pwd; +cd(direc); +s = dir(opt); +if isempty(s), + disp('getfnames: no data'); + return; +end + +n = length(s); +i = 1; +j = 1; +for k=1:n, + if s(k).isdir, + dn{j,1} = s(k).name; + j = j + 1; + else + fn{i,1} = s(k).name; + i = i + 1; + end +end + cd(cur_dir) +%[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 @@ +% function f = getimage2(imagefile) returns a normalized intensity image. +% If the file postfix is not given, then I will search any possible image file +% under the IMAGE_DIR. + +% Stella X. Yu, March 1999 + +function f = getimage2(imagefile) + +if exist(imagefile)==2, + g = {imagefile}; +else + g = {}; +end +globalenvar; +g = [g; getfnames(IMAGE_DIR,[imagefile,'.*'])]; + +j = 1; +for i=1:length(g), + k = findstr(g{i},'.'); + gp = g{i}(k(end)+1:end); + if strcmp(gp,'ppm'), + f = double(readppm(g{i})); + j = 0; + elseif sum(strcmp(gp,{'jpg','tif','jpeg','tiff','bmp','png','hdf','pcx','xwd'}))>0, + f = double(imread(g{i})); + j = 0; + end + if j==0, + disp(sprintf('This is an image read from %s under %s',g{i},IMAGE_DIR)); + break; + end +end +if j, + f = []; + disp('Image not found'); + return; +end + +if size(f,3)>1, + %f = sum(f,3)./3; + f = rgb2ntsc(f); + f = f(:,:,1); +end +minf = min(f(:)); +maxf = max(f(:)); +f = (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 @@ +% globalenvar + +HOME_DIR = '/hid/jshi/Research/walking/stella'; +IMAGE_DIR = '/hid/jshi/test_images'; +C_DIR = '/hid/jshi/Research/Ncut_code_C'; +IS_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 @@ +% function [par, rec_num] = jshincut(par,image_dir) +% Input: +% par = a structure with parameters for command_ncut.tex +% image_dir = the directory where the imagefile is stored +% Output: +% par = parameters used +% rec_num = record number in the NCut database +% Jianbo Shi's ncut_IC is applied to the image +% (If there is no .ppm format for the named image, +% conversion from related files would be attempted.) +% Results are organized according to the parameters. +% Example: jshincut('240018s'); +% See also: jshincutdefpar; ncutcheckin +% Set IS_PC according to your platform in globalenvar.m + +% Stella X. Yu, 2000. + +function [par,rec_num] = jshincut(par,image_dir) + +rec = jshincutdefpar; + +fields = fieldnames(rec); +nf = length(fields); + +if ischar(par), + imagename = par; + par = rec; + par.fname_base = imagename; +end + +globalenvar; + +if nargin<2 | isempty(image_dir), + image_dir = IMAGE_DIR; +end + +imagename = getfield(par,fields{1}); +for i=2:nf, + t = getfield(par,fields{i}); + if isempty(t), + par = setfield(par,fields{i},getfield(rec,fields{i})); + end +end + +% dir and filename +catchar = {'/','\'}; +catchar = catchar{IS_PC+1}; + +% first check if there is a ppm file for this image +if not(exist([image_dir,catchar,imagename,'.ppm'])), + j = getfnames(image_dir,[imagename,'.*']); + if isempty(j), + disp('Image not found.'); + return; + end + k = 0; + for i=1:length(j), + k = k + not(isempty(im2ppm(j{i},image_dir))); + if k==1, + disp(sprintf('%s -> %s.ppm succeeded.',j{i},imagename)); + break; + end + end + if k==0, + disp('Sorry. Attempt to convert your named image into ppm format failed.'); + return; + end +end + +cd(C_DIR); + +% generate command_ncut.tex file +fn = 'command_ncut.tex'; +fid = fopen(fn,'w'); +fprintf(fid,'%21s\t%s%c%s\n',fields{1},image_dir,catchar,imagename); +for i=2:nf, + t = getfield(par,fields{i}); + if isnumeric(t), + t = num2str(t); + end + fprintf(fid,['%21s\t%s\n'],fields{i},t); +end +fclose(fid); +%disp('You can check and modify command_ncut.tex before I run ncut_IC on it. Good?');pause(1); + +% run ncut_IC +unix(['.',catchar,'ncut_IC']); +cd(HOME_DIR); + +% check in +copyfile([C_DIR,catchar,fn],[image_dir,catchar,fn]); +rec_num = ncutcheckin(fn,image_dir,image_dir); +%delete([image_dir,catchar,imagename,'.ppm']); +%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 @@ +% function rec = jshincutdefpar; +% default parameter setting for Jianbo Shi's NCut C codes + +% Stella X. Yu, 2000. + +function rec = jshincutdefpar; + +rec.fname_base = '240018s'; +rec.fname_ext = 'ppm'; +rec.num_eigvecs = 15; +rec.spatial_neighborhood_x=20; +rec.sigma_x= 10; +rec.sig_I= -0.16; +rec.sig_IC= 0.01; +rec.hr= 2; +rec.eig_blk_sze= 3; +rec.power_D= 1; +rec.offset = 0.0; +rec.sig_filter = 1.0; +rec.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 @@ +% function rec_num = ncutcheckin(fn,sdir,tdir) +% Input: +% fn = parameter file name, default = 'command_ncut.tex' +% sdir = source dir for fn as well as data files +% tdir = target dir to check in, both default = IMAGE_DIR +% Output: +% rec_num = the number of current parameter records +% The imagefile_par.m is updated if fn contains a new +% parameter set. Data files are tagged and copied over to +% a subdir under tdir. +% Example: ncutcheckin; +% Set IS_PC, IMAGE_DIR according to your platform in globalenvar.m + +% Stella X. Yu, 2000. + +function rec_num = ncutcheckin(fn,sdir,tdir) + +globalenvar; + +cur_dir = pwd; + +if nargin<1 | isempty(fn), + fn = 'command_ncut.tex'; +end + +if nargin<2 | isempty(sdir), + sdir = IMAGE_DIR; +end + +if nargin<3 | isempty(tdir), + tdir = IMAGE_DIR; +end + +rec = jshincutdefpar; + +% first, generate a parameter record from fn +cd(sdir); +[names,values] = textread(fn,'%s %s','commentstyle','shell'); +n = length(names); +s = rec; +for i=1:n, + j = str2num(values{i}); + if isempty(j), + s = setfield(s,names{i},values{i}); + else + s = setfield(s,names{i},j); + end +end +cd(cur_dir); + +% special care to extract the image file name +imagename = getfield(s,names{1}); +catchar = {'/','\'}; +catchar = catchar{IS_PC + 1}; +k = max([0,findstr(imagename,catchar)]); +imagename = imagename(k+1:end); +s = setfield(s,names{1},imagename); + +% second, check if the target dir contains a profile for the image +cd(tdir); +if not(exist(imagename,'dir')), + mkdir(imagename); + cd(cur_dir); + j = [catchar,imagename,'.',getfield(s,names{2})]; + copyfile([sdir,j],[tdir,catchar,imagename,j]); + cd(tdir); +end +cd(imagename); +j = [imagename,'_par']; +if not(exist(j)), + rec_num = 1; + p = s; +else + % load par file + feval(j); + rec_num = length(p); + i = 1; + while (i<=rec_num), + k = 0; + for j=1:n, + k = k + sum(getfield(s,names{j})-getfield(p(i),names{j})); + end + if k==0, + if not(isempty(input(['Data already existed as record # ',num2str(i),... + '\nPress any non-return key to Overwrite'],'s'))), + break; + else + rec_num = i; % have checked in already, no update + cd(cur_dir); + return; + end + else + i = i + 1; + end + end + rec_num = i; % new parameter setting + p(rec_num)=s; +end +tdir = [tdir,catchar,imagename]; +cd(cur_dir); + +% third, check in data files +% leave .ppm and _edgecon, _phase files +% if not(exist([tdir,catchar,imagename,'.ppm'])), +% copyfile([sdir,catchar,imagename,'.ppm'],[tdir,catchar,imagename,'.ppm']); +% end + +% IC files only +dn = getfnames(sdir,[imagename,'*_IC*.*']); +header = sprintf('%s%c%s_%d_',tdir,catchar,imagename,rec_num); +j = length(imagename)+2; +k = length(dn); +for i=1:k, + copyfile([sdir,catchar,dn{i}],[header,dn{i}(j:end)]); + delete([sdir,catchar,dn{i}]); +end +disp(sprintf('%d files checked in as record #%d',k,rec_num)); + + +% finally, update parameter file +cd(tdir); +fid = fopen([imagename,'_par.m'],'w'); +fprintf(fid,'%% Last checked in at %s\n\n',datestr(now)); +for i=1:rec_num, + for j=1:n, + k = getfield(p(i),names{j}); + if ischar(k), + fprintf(fid,'p(%d).%s=\''%s\'';\n',i,names{j},k); + else + fprintf(fid,'p(%d).%s=%s;\n',i,names{j},num2str(k)); + end + end + fprintf(fid,'\n'); +end +fclose(fid); +cd(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 @@ +% function openfigure(m,n,caption,isnew) +function h = openfigure(m,n,caption,isnew) + +if nargin<3, + caption = ' '; +end + +if nargin<4, + isnew = 1; +end + +if (m<=0 | n<=0) + return; +end + +if isnew, + h = figure; colormap(gray); +else + h = gcf; +end +clf + +subplot('position',[0,0,0.1,0.1]); axis off; +text(0.1,0.15,sprintf('S. X. Yu, %s',date),'FontSize',8); + +subplot('position',[0,0.96,0.1,0.1]); axis off; +text(0.1,0.15,caption,'FontSize',8); + +subplot(m,n,1); +%return + +if (m==1 & n==1), + return; +end + +%set(gcf,'PaperPosition',[0.25, 8, 8,2.5*m]); +% set(gcf,'PaperPosition',[0.25,0.25,8,10.5]); +%return + +if (m<=n), + set(gcf,'PaperOrientation','landscape','PaperPosition',[0.25,0.25,10.5,8]); +else + set(gcf,'PaperPosition',[0.25,0.25,8,10.5]); +end + +% comment on PaperPosition +% [a,b,c,d] +% (a,b) is the coordinate of the lower-left corner of the figure +% (a,b) = (0,0) is the lower-left corner of the paper +% (c,d) is the coordinate of the upper-right corner of the figure relative to the lower-left corner of the figure +% Therefore, c>=a, d>=b +% 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 @@ +% function showim(f,cmap) display real or complex image. +% When it is complex, the real part and imaginary part +% are displayed as [real,imag] in one image. +% cmap is the colormap. default = gray, -1 = inverted gray. + +% Stella X. Yu, 2000. + +function showim(f,cmap,ishori) + +if not(isreal(f)), + i = [real(f(:)); imag(f(:))]; + j = [min(i), max(i)]; + [nr,nc] = size(f); + if nargin<3 | isempty(ishori), + ishori = nr>nc; + end + if ishori, + i = zeros(nr,1); + f = [real(f), [i+j(1),i+j(2)], imag(f)]; + else + i = zeros(1,nc); + f = [real(f); [i+j(1);i+j(2)]; imag(f)]; + end +end +imagesc(f); axis off; axis image; + +if nargin<2 | isempty(cmap), + return; +end + +if cmap==1, + cmap = gray; +elseif cmap==-1, + cmap = flipud(gray); +end +colormap(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 @@ +% function [g,lgd,v,s,dd] = showncut(fn,rec_num) +% Input: +% fn = file / image name +% rec_num = Ncut record number +% Output: +% g = a cell contains 1D, 2D and 3D embeddings +% lgd = legend for g +% v = eigenvectors +% s = eigenvalues +% dd = normalization matrix = 1/sqrt(rowsum(abs(a))) +% an image is displayed + +function [g,lgd,v,s,dd] = showncut(fn,rec_num) + +globalenvar; cd(IMAGE_DIR);cd(fn); feval([fn,'_par']);cd(HOME_DIR); +par = p(rec_num); +no_rep = (par.offset<1e-6); + +[v,s,dd] = firstncut(fn,rec_num); +[m,n,nc] = size(v); + +% generate images for display +nr = 5; +num_plots = nc * nr; +g = cell(num_plots,1); +lgd = g; +names = {'r','\theta','\phi'}; +x = cell(3,1); +for j=1:nc, + g{j} = v(:,:,j); + lgd{j} = sprintf('%s_{%d} = %1.2f','\lambda', j+no_rep, s(j)); + + if j0) & y>0; + % showmask(f,mask); +end -- cgit v1.2.2