K-means clustering ignoring zero values

조회 수: 2 (최근 30일)
pmoreira
pmoreira 2012년 10월 30일
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
Image Analyst
Image Analyst 2012년 10월 30일
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 2012년 10월 31일
Hi, Image Analyst. I perform kmeans on image, just follwing this tutorial:
The problem is that I need to ignore the zeros values.
Tks

댓글을 달려면 로그인하십시오.

답변 (1개)

Tom Lane
Tom Lane 2012년 11월 1일
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!

Translated by