무게 중심은 이미지의 좌표가 아니고 형상 공간의 좌표와 일치합니다. kmeans가 얼마나 잘 수행되었는지 테스트 할 수있는 두 가지 방법이 있습니다. 두 가지 방법 모두, 가장 가까운 클러스터와 포인트를 연결하고 싶을 것입니다. 이 정보는 kmeans의 첫 번째 출력에서 가져옵니다.
(1) 6 차원 공간을 2 차원 또는 3 차원 공간으로 축소 한 다음 서로 다른 색으로 분류 된 좌표를 플로팅하여 클러스터링 결과를 시각화 할 수 있습니다.
%# kmeans clustering
[idx,centroids6D] = kmeans(featureArray,nClusters);
%# find the dissimilarity between features in the array for mdscale.
%# Add the cluster centroids to the points, so that they get transformed by mdscale as well.
%# I assume that you use Euclidean distance.
dissimilarities = pdist([featureArray;centroids6D]);
%# transform onto 3D space
transformedCoords = mdscale(dissimilarities,3);
%# create colormap with nClusters colors
cmap = hsv(nClusters);
%# loop to plot
figure
hold on,
for c = 1:nClusters
%# plot the coordinates
currentIdx = find(idx==c);
plot3(transformedCoords(currentIdx,1),transformedCoords(currentIdx,2),...
transformedCoords(currentIdx,3),'.','Color',cmap(c,:));
%# plot the cluster centroid with a black-edged square
plot3(transformedCoords(1:end-nClusters+c,1),transformedCoords(1:end-nClusters+c,2),...
transformedCoords(1:end-nClusters+c,3),'s','MarkerFaceColor',cmap(c,:),...
MarkerEdgeColor','k');
end
: 특징 벡터가
featureArray
라는 배열에 수집되고, 말,로 데이터를 변환
mdscale을 사용하여 다음과 같이
nClusters
클러스터를 요청, 당신은, 3D 공간을 플롯 할 거라고 가정하면
(2) 당신은 대안있는 클러스터
는 nRows
nCols
에 의해 블록이 있다고 가정하면, 당신은
쓰기에 속하는 이미지의 어떤 부분을 보여줍니다 의사 컬러 이미지를 만들 수 있습니다3210
%# kmeans clustering
[idx,centroids6D] = kmeans(featureArray,nClusters);
%# create image
img = reshape(idx,nRows,nCols);
%# create colormap
cmap = hsv(nClusters);
%# show the image and color according to clusters
figure
imshow(img,[])
colormap(cmap)