clustering image, grayscale image
Show older comments
Hello, I have for example image

I want convert to grayscale image, and then use Kmeans method.
Does anyone help ?
Thanks.
Answers (2)
Image Analyst
on 15 Mar 2014
0 votes
Use rgb2gray() from the Image Processing Toolbox. Then kmeans() from the Statistical Toolbox. Here's a demo: http://www.mathworks.com/products/demos/image/color_seg_k/ipexhistology.html
16 Comments
Tomas
on 15 Mar 2014
Image Analyst
on 15 Mar 2014
First tell me what you think your two clusters represent. What are the two axes - what are their units?
Image Analyst
on 15 Mar 2014
Edited: Image Analyst
on 15 Mar 2014
Then why are you converting to grayscale???? It doesn't make sense. Can you explain?
Why don't you try this File Exchange submission that looks like what you want to achieve: http://www.mathworks.com/matlabcentral/fileexchange/37197-dem-diffused-expectation-maximisation-for-image-segmentation

Tomas
on 15 Mar 2014
Image Analyst
on 15 Mar 2014
Again, that does not make sense. It's an image. Each pixel has a position specified by what row and columns it's in. What do you mean by "obtain the position of pixels"? For example, look at this small image of only 4 pixels:
123 234
73 37
Now if I were to ask you "give me the position of pixels in that image", what would you answer?
Tomas
on 15 Mar 2014
Image Analyst
on 15 Mar 2014
We can't help you unless you can accurately say what you want. The best I could do was to show you a color classification method that seemed to produce something similar to what you showed that you want.
Tomas
on 15 Mar 2014
Image Analyst
on 16 Mar 2014
But do we really need to carry out this same conversation in two different threads? Respond to each of them and let me know which one you will continue with and which you will abandon, because I don't want to monitor two threads on the same thing and answer the same thing twice.
Tomas
on 16 Mar 2014
Image Analyst
on 16 Mar 2014
I don't know what your question is, if any. And I'm having trouble matching your mindset. A gray level is a 2D image. Even if you plot it as a 2.5D surface where the height above the plane is the gray level, it's still a 2D image because there are two independent variables (row & column) and one dependent variable (the gray level). In 1D, if I had a vector [3,5,8,16,22] everyone says that's a 1D vector, not a 2D signal just because you could plot that values along the y axis and the index along the x axis. Or consider a sine wave - it's a 1D signal, not a 2D signal just because you plot it in the x,y plane.
I don't how you used kmeans. You simply have a colormap applied. You just say that if the gray level is less than about 64, make it red, and if it's between 64 and 145 it's green, and if it's greater than 145 it's blue. You don't need kmeans for that, you can use ind2rgb(). And I don't know what you did for the color image, for example did you use rgb2gray(), rgb2hsv() and use the v channel, or did you just take one of the color channels, or something else. Anyway, I'm not sure if you have a question or if we're done. I don't have the stats toolbox so I can't actually try any code with kmeans() in it.
Tomas
on 16 Mar 2014
Image Analyst
on 16 Mar 2014
Sorry I don't understand the language. I don't know what to click, and it started spewing out a bunch of stuff that I didn't know what it was into the command window. It went on for several minutes and I couldn't stop it, not even with control-C. I had to go into task manager to finally kill off MATLAB.
I suggest you try normal debugging operations to figure out what's going on.
Boni_Pl
on 12 Nov 2016
0 votes
Please anyone upload a matlab code for kmeans clustering of an ultrasound image.
Categories
Find more on k-Means and k-Medoids Clustering in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!




