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/textons/find_textons.m | 46 ++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100755 SD-VBS/common/toolbox/toolbox_basic/textons/find_textons.m (limited to 'SD-VBS/common/toolbox/toolbox_basic/textons/find_textons.m') diff --git a/SD-VBS/common/toolbox/toolbox_basic/textons/find_textons.m b/SD-VBS/common/toolbox/toolbox_basic/textons/find_textons.m new file mode 100755 index 0000000..e7fa4b0 --- /dev/null +++ b/SD-VBS/common/toolbox/toolbox_basic/textons/find_textons.m @@ -0,0 +1,46 @@ +function [centers,label,post,d2]=find_textons(FIw,ncenters,centers_in,n_iter); +% [centers,label,post,d2]=find_textons(FIw,ncenters,centers_in,n_iter); +% +% find textons using kmeans for windowed portion FIw of filtered image +% +% to start with centers pulled randomly from image, set centers_in=[] + +% define number of textons +%ncenters=25; + +[N1,N2,N3]=size(FIw); +% reshape filtered image stack into a long array of feature vectors +fv=reshape(FIw,N1*N2,N3); +% (each row is a feature vector) + +%centers=.01^2*randn(ncenters,N3); +% take centers randomly from within image +if isempty(centers_in) + rndnum=1+floor(N1*N2*rand(1,ncenters)); + centers_in=fv(rndnum,:); +end + +options = foptions; +options(1)=1; % Prints out error values. +options(5) = 0; +if nargin<4 + n_iter=15; +end +options(14) = n_iter; % Number of iterations. + +[centers,options,d2,post]=kmeans2(centers_in,fv,options); + +% reshuffle the centers so that the one closest to the origin +% (featureless) comes last +norms=sum(centers.^2,2); +[sortval,sortind]=sort(-norms); +centers=centers(sortind,:); +d2=reshape(d2,N1,N2,ncenters); +post=reshape(post,N1,N2,ncenters); +d2=d2(:,:,sortind); +post=post(:,:,sortind); + + +% retrieve cluster number assigned to each feature vector +[minval,label]=min(d2,[],3); + -- cgit v1.2.2