image segmentation help
1 回表示 (過去 30 日間)
古いコメントを表示
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)
0 件のコメント
採用された回答
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!