フィルターのクリア

How can I classify the image pixels into two classes only using Kmeans algorithm?

1 回表示 (過去 30 日間)
I have gray-level image, I need to use Kmeans in MatLab to convert this image into binary image.

採用された回答

Akira Agata
Akira Agata 2017 年 10 月 23 日
I think the solution would be like this:
% Read gray-scale image
I = imread('cameraman.tif');
% Clustering by k-means
x = double(I(:));
[idx, center] = kmeans(x,2);
% Make binary image
[nrow,ncol] = size(I);
labels = reshape(idx,nrow,ncol);
BW = labels == 1;
% Show the result
imshowpair(I,BW,'montage')
  10 件のコメント
Iremsu Savas
Iremsu Savas 2018 年 10 月 24 日
why do we need to convert the image to the double version?
Image Analyst
Image Analyst 2018 年 10 月 24 日
When computing distances between points, you don't want the result to be integer because the precision won't be that accurate, and if the inputs were integers the output would be also.
I guess they want you to do the conversion before calling rather than the function doing it itself internally.

サインインしてコメントする。

その他の回答 (1 件)

Image Analyst
Image Analyst 2017 年 10 月 26 日

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by