image segmentation help

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