I have this code for clustering the data set which is running successfilly but i want to use this code for image segmentation.
I need your help, plz help me....
Thnks in advance
function y=kMeansCluster(m,k,isRand)
if nargin<3, isRand=0; end
if nargin<2, k=1; end
[maxRow, maxCol]=size(m)
if maxRow<=k,
y=[m, 1:maxRow];
else
if isRand,
p = randperm(size(m,1));
for i=1:k
c(i,:)=m(p(i),:)
end
else
for i=1:k
c(i,:)=m(i,:)
end
end
temp=zeros(maxRow,1);
while 1,
d=DistMatrix(m,c)
[z,g]=min(d,[],2)
if g==temp,
break;
else
temp=g;
end
for i=1:k
f=find(g==i)
if f
c(i,:)=mean(m(find(g==i),:),1)
end
end
end
y=[m,g]
end
function d=DistMatrix(A,B)
[hA,wA]=size(A);
[hB,wB]=size(B);
if wA ~= wB, error(' second dimension of A and B must be the same'); end
for k=1:wA
C{k}= repmat(A(:,k),1,hB);
D{k}= repmat(B(:,k),1,hA);
end
S=zeros(hA,hB);
for k=1:wA
S=S+(C{k}-D{k}').^2;
end
d=sqrt(S)

 채택된 답변

Image Analyst
Image Analyst 2012년 2월 27일

0 개 추천

Here's a Mathworks example where they've used k-means clustering for color segmentation: http://www.mathworks.com/products/demos/image/color_seg_k/ipexhistology.html

추가 답변 (0개)

카테고리

도움말 센터 및 File Exchange에서 Statistics and Machine Learning Toolbox에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by