Borrar filtros
Borrar filtros

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

1 visualización (últimos 30 días)
I have gray-level image, I need to use Kmeans in MatLab to convert this image into binary image.

Respuesta aceptada

Akira Agata
Akira Agata el 23 de Oct. de 2017
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 comentarios
Iremsu Savas
Iremsu Savas el 24 de Oct. de 2018
why do we need to convert the image to the double version?
Image Analyst
Image Analyst el 24 de Oct. de 2018
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.

Iniciar sesión para comentar.

Más respuestas (1)

Image Analyst
Image Analyst el 26 de Oct. de 2017

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by