kmeans with RGB space

Dear colleague,
I have a problem with function kmeans. I have used it with RGB space but it don´t run. I did:
1) Y=imread('1.jpg.'); where Y is RGB image (1960x1960x3)
r=Y(:,:,1);
g=Y(:,:,2);
b=Y(:,:,3);
vector=[r(:) g(:) b(:)];
[Idx,c]=kmeans(vector,3); because I want three regions.
However it don´t run good. It give Idx as a vector with centroid in place of a label matrix.
Below I tried this :
A=zeros (3841600,3);Y=double(Y);
A(:,1)=Y(:,:,1);
A(:,2)=Y(:,:,2);
A(:,3)=Y(:,:,3)
but it isn´t correct.
Finally I tried to change it directly with:
A=reshape(Y,3841600,1,3)
but it didn´t run.
What is the matter? Could anyone help me, please?

 Respuesta aceptada

Image Analyst
Image Analyst el 29 de Jul. de 2011

0 votos

Follow MATLAB's turorial here http://www.mathworks.com/products/demos/image/color_seg_k/ipexhistology.html The only difference is that their works in lab color space while you want to work in rgb color space, so just skip the rgb to lab conversion step in their demo.

2 comentarios

Cristina
Cristina el 1 de Ag. de 2011
Dear colleague, Thanks for the reply. The solution is: Always that I use kmeans function I must convert the RGB space to lab color space. Why does not kmeans function run directly with the RGB space? I want to capture features of RGB space of image
Image Analyst
Image Analyst el 6 de Nov. de 2011
Like I said, it will work on RGB color space also. I don't know why you say that you must convert to lab color space.

Iniciar sesión para comentar.

Más respuestas (0)

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by