k-means clustering in Image Processing

2 views (last 30 days)
Hi, i'm doing k-mean clustering on an image (fruit tree image) with k=4 clusters. when i display 4 clusters seperately, fruits goes to cluster1, stem goes to cluster 2, leaves goes to clster3 and background goes to cluster4. i'm further interested in fruit clutser only. the probelm is when i change image to another fruit tree image, fruit cluster goes to cluster2 or sometimes to clsuter3 or 4. my wish is to not change the cluster for fruit, means if fruit is in cluster1 it should be in cluster1 in all images of fruit tree. how can i do that? 2ndly if its not possible i want to select that cluster automatically which contains fruit. how can i do that? thanks in advance.

Answers (1)

Image Analyst
Image Analyst on 27 Jun 2021
You're right - the class numbers are random. You can reorder your clusters to the class number you want after you've called kmeans. See attached demo.
In the above demo, the original class numbers are shown on the left. But let's say I wanted them to go in order of distance from the origin. So I relabeled them and got the cluster labels shown on the right.
  2 Comments
Hafiz Muhammad Tayyab Abbas
Edited: Hafiz Muhammad Tayyab Abbas on 28 Jun 2021
Great work, but how it work for images using imsegkmeans? as i want same process for images. Thanks in advance for help.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!