summaryrefslogtreecommitdiffstats
path: root/SD-VBS/common/toolbox/toolbox_basic/textons/find_textons.m
diff options
context:
space:
mode:
authorLeo Chan <leochanj@live.unc.edu>2020-10-22 01:53:21 -0400
committerJoshua Bakita <jbakita@cs.unc.edu>2020-10-22 01:56:35 -0400
commitd17b33131c14864bd1eae275f49a3f148e21cf29 (patch)
tree0d8f77922e8d193cb0f6edab83018f057aad64a0 /SD-VBS/common/toolbox/toolbox_basic/textons/find_textons.m
parent601ed25a4c5b66cb75315832c15613a727db2c26 (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/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