K means clustering in MATLAB - output image

穿精又带淫゛_ 提交于 2019-12-06 11:48:32

A: Given that your matrix output contains scalar values ranging from 1 to 3, imshow(output) is treating this as a grayscale matrix and assuming that the full range of values is 0 to 255. This is why constraining the color limits is necessary as otherwise your image is all white or almost all white.

B: output = output - 1

As pointed out by Ryan, your problem is probably just how you display the image. Here's a working example:

snow = rand(256, 256);
figure;
imagesc(snow);

nClusters = 3;
clusterIndices = kmeans(snow(:), nClusters);

figure;
imagesc(reshape(clusterIndices, [256, 256]));
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!