Filter löschen
Filter löschen

I am trying to use K-means on a grayscale image

1 Ansicht (letzte 30 Tage)
Iremsu Savas
Iremsu Savas am 24 Okt. 2018
Erneut geöffnet: Star Strider am 24 Okt. 2018
Hello all, When I try the following code I get just a white figure as a result. Is there something that I skip or is there a way to fix this? Thank you
I = imread('lena.bmp');
figure(1)
imshow(I);
I = im2double(I);
c = kmeans(I(:),35);
I = reshape(c, size(I));
figure(2);
imshow(I);

Akzeptierte Antwort

KSSV
KSSV am 24 Okt. 2018
I = uint8(I) ;
imshow(I);

Weitere Antworten (1)

Adam
Adam am 24 Okt. 2018
Without being able to run your code (I don't have 'lena.bmp' and can't be bothered to try to find it!), I is going to be of type double, but will contain integer values for the indices of your classes.
imshow, when given an image of type double expects their values to be between 0 and 1 so everything above 1 is saturated as white.
Either cast to an integer, scale down to 0 to 1 or use something like imagesc with a colourmap instead.

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by