image segmentation help
Afficher commentaires plus anciens
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)
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Color Segmentation dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!