Effacer les filtres
Effacer les filtres

grayscale image clustering, show ouput image from matrix

1 vue (au cours des 30 derniers jours)
Tomas
Tomas le 26 Avr 2014
Commenté : Image Analyst le 13 Mar 2018
Hello, I want a grayscale image clustering according intersity colors from 0-255.
my code:
I = imread('obraz1.png');
I=rgb2gray(I);
imshow(I);
title('Grayscale image','FontSize',16,'Color','k');
I=double(I);
maxi=max(I(:));
I=I./maxi;
[m n]=size(I);
P = [];
for i=1:m
for j=1:n
if I(i,j)<1 %%All except white
P=[P; i j ];
end
end
end
size(P);
MON=P;
[IDX]= kmeans(MON,3,'emptyaction','singleton')
how do i display image after clustering ?

Réponses (1)

Image Analyst
Image Analyst le 27 Avr 2014
I'd guess create a classified image by going down IDX and setting the value of the classified image to either 1, 2, or 3 for each pixel, depending on what class it is.
  3 commentaires
Image Analyst
Image Analyst le 28 Avr 2014
I don't have the Statistics Toolbox so I can't be sure but don't you think it would go like this
classifiedImage = zeros(size(I), 'int32');
for p = 1 : length(IDX)
row = P(p, 1);
column = P(p, 2);
% Set this pixel of the classified image
% to the class it identified for that pixel.
classifiedImage(row, column) = IDX(p);
end
I've never used kmeans since I don't have the toolbox but I just read the documentation for a minute and that's what I came up with. It seemed really really obvious to me, though it's probably not right since you worked on it for a whole week, so what I came up with in less than a minute can't be right. But for what it's worth, that's my best guess.
Tomas
Tomas le 28 Avr 2014
Modifié(e) : Tomas le 28 Avr 2014
Thank you it works. it is logically correct final image compared to the input image ?
Thank you for your feedback.
input image
output image

Connectez-vous pour commenter.

Community Treasure Hunt

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

Start Hunting!

Translated by