回覆列表
-
1 # a不會愛的小笨蛋
-
2 # 何以笙丶丶
function[labels]=kmeans_clustering(data,k)
[num,~]=size(data);
ind=randperm(num);
ind=ind(1:k);
centers=data(ind,:);
d=inf;
labels=nan(num,1);
whiled>0
labels0=labels;
dist=pdist2(data,centers);
[~,labels]=min(dist,[],2);
d=sum(labels0~=labels);
fori=1:k
centers(i,:)=mean(data(labels==i,:),1);
end
end
end
% 可能是聚類後的影象資料不匹配,用如下程式碼試試 iidx = uint8(iidx);level = graythresh(iidx);imageout = im2bw(iidx,level);imshow(imageout);