# how do i only use the green cluster on this 3 clustering?

1 view (last 30 days)
Keane Athallah on 22 May 2022
Answered: Image Analyst on 23 May 2022
in diffrent image sometime the Leaves cluster are appear on cluster 1 or 2, i want to compare the cluster object so that it only leaves cluster that i use in the next code, i wonder how can i do that. thank you
Walter Roberson on 22 May 2022
How are you doing the clustering?

Image Analyst on 22 May 2022
If you're using kmeans() I don't think you can specify any rule in advance for what cluster has what data. You'd have to do that afterwards to renumber the clusters if you need to or want to.
Attached is a demo that does kmeans clustering to reassign the random numbering of the clusters according to two rules. First I numbered them according to the distance of the cluster centroid from the origin. In the second case I renumbered them according to the number of points in each cluster, from 1 being the smallest to 4 being the largest number of points.
Keane Athallah on 23 May 2022
how can i specify the number clustering, for example i want the green only appear on cluster 3?
Walter Roberson on 23 May 2022
In order to do that, you will need to either write your own algorithm, or else you will need to find an implementation of kmeans and customize it somehow.
The algorithm for kmeans makes no attempt to retain some kind of "identity" for a given cluster number. There are cases where clusters can turn out to pretty much exchange identities.
Speaking fairly approximately, the situation can be similar to what can happen when you have three interacting bodies: momentum from one body can move two other bodies out of place, and by the time the first object has moved into its proper places, the other two bodies happen to be closer to each other's original position and so settle back close to the original positions but exchanged.
Therefore even if you use the options to provide starting centroids with the third cluster being where something green is, then there is no certainty that the association with green would continue to be with the third cluster -- it could end up on any cluster.
The usual way to handle this is to post-process, have some way to detect which cluster is associated with which notable trait, and then exchange cluster numbers.

Image Analyst on 23 May 2022
I'm not sure you're doing clustering. You may be using the Color Thresholder app on the Apps tab of the tool ribbon to do color segmentation to get masks for certain color ranges. Then you're doing "connected components labeling" which labels blobs from top down, then left to right. Attached is an explanatory demo for how labeling assigns its numbers.

### 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!