kmeans with RGB space
1 view (last 30 days)
Show older comments
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?
0 Comments
Accepted Answer
Image Analyst
on 29 Jul 2011
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 Comments
Image Analyst
on 6 Nov 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.
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!