summaryrefslogtreecommitdiffstats
path: root/SD-VBS/common/toolbox/toolbox_basic/textons/find_textons.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/textons/find_textons.m
parent47ced4e96bbb782b9e780e8f2cfc637b2c21ff44 (diff)
initial sd-vbs
initial sd-vbs add sd-vbs sd-vbs
Diffstat (limited to 'SD-VBS/common/toolbox/toolbox_basic/textons/find_textons.m')
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/textons/find_textons.m46
1 files changed, 46 insertions, 0 deletions
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 @@
1function [centers,label,post,d2]=find_textons(FIw,ncenters,centers_in,n_iter);
2% [centers,label,post,d2]=find_textons(FIw,ncenters,centers_in,n_iter);
3%
4% find textons using kmeans for windowed portion FIw of filtered image
5%
6% to start with centers pulled randomly from image, set centers_in=[]
7
8% define number of textons
9%ncenters=25;
10
11[N1,N2,N3]=size(FIw);
12% reshape filtered image stack into a long array of feature vectors
13fv=reshape(FIw,N1*N2,N3);
14% (each row is a feature vector)
15
16%centers=.01^2*randn(ncenters,N3);
17% take centers randomly from within image
18if isempty(centers_in)
19 rndnum=1+floor(N1*N2*rand(1,ncenters));
20 centers_in=fv(rndnum,:);
21end
22
23options = foptions;
24options(1)=1; % Prints out error values.
25options(5) = 0;
26if nargin<4
27 n_iter=15;
28end
29options(14) = n_iter; % Number of iterations.
30
31[centers,options,d2,post]=kmeans2(centers_in,fv,options);
32
33% reshuffle the centers so that the one closest to the origin
34% (featureless) comes last
35norms=sum(centers.^2,2);
36[sortval,sortind]=sort(-norms);
37centers=centers(sortind,:);
38d2=reshape(d2,N1,N2,ncenters);
39post=reshape(post,N1,N2,ncenters);
40d2=d2(:,:,sortind);
41post=post(:,:,sortind);
42
43
44% retrieve cluster number assigned to each feature vector
45[minval,label]=min(d2,[],3);
46