K-means clustering ignoring zero values

6 views (last 30 days)
pmoreira
pmoreira on 30 Oct 2012
I have an image with a large number of zeros. I am trying to use the kmeans clustering but I would like to ignore those zero values. Does someone know how to do it? Tks
  2 Comments
Image Analyst
Image Analyst on 30 Oct 2012
That doesn't make sense. How are you doing kmeans on the image? Where did you upload your image to so we can see what you're talking about? Are you trying to group non-zero pixels according to spatial location? If so, have you tried using morphology like imclose() and imreconstruct()?
pmoreira
pmoreira on 31 Oct 2012
Hi, Image Analyst. I perform kmeans on image, just follwing this tutorial:
The problem is that I need to ignore the zeros values.
Tks

Sign in to comment.

Answers (1)

Tom Lane
Tom Lane on 1 Nov 2012
In that demo clustering is performed on the variable ab, then the result are reshaped and put into the variable pixel_labels.
I don't have the Image Processing Toolbox handy at the moment. But I would create a variable idx that is the row numbers of ab that are not all zero. Then I would create an output pixel_labels as zeros of the proper shape. Then I would store the result of clustering ab(idx,:) into pixel_labels(idx).
Try it, then tell me if I'm wrong.

Community Treasure Hunt

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

Start Hunting!