image segmentation help

1 次查看(过去 30 天)
pdp rpa
pdp rpa 2012-2-27
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
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 个)

标签

Community Treasure Hunt

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

Start Hunting!

Translated by