diff options
Diffstat (limited to 'SD-VBS/common/toolbox/toolbox_basic/textons/find_textons.m')
| -rwxr-xr-x | SD-VBS/common/toolbox/toolbox_basic/textons/find_textons.m | 46 |
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 @@ | |||
| 1 | function [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 | ||
| 13 | fv=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 | ||
| 18 | if isempty(centers_in) | ||
| 19 | rndnum=1+floor(N1*N2*rand(1,ncenters)); | ||
| 20 | centers_in=fv(rndnum,:); | ||
| 21 | end | ||
| 22 | |||
| 23 | options = foptions; | ||
| 24 | options(1)=1; % Prints out error values. | ||
| 25 | options(5) = 0; | ||
| 26 | if nargin<4 | ||
| 27 | n_iter=15; | ||
| 28 | end | ||
| 29 | options(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 | ||
| 35 | norms=sum(centers.^2,2); | ||
| 36 | [sortval,sortind]=sort(-norms); | ||
| 37 | centers=centers(sortind,:); | ||
| 38 | d2=reshape(d2,N1,N2,ncenters); | ||
| 39 | post=reshape(post,N1,N2,ncenters); | ||
| 40 | d2=d2(:,:,sortind); | ||
| 41 | post=post(:,:,sortind); | ||
| 42 | |||
| 43 | |||
| 44 | % retrieve cluster number assigned to each feature vector | ||
| 45 | [minval,label]=min(d2,[],3); | ||
| 46 | |||
