Problem in kmeans, image segmentation algorithm.
1 view (last 30 days)
Show older comments
In K-means clustering using tutorial
images we get after clustering are random as cluster centers are randomly selected. I am using this code to land use and land cover analysis where regions such as green/forest area, water area, soil area road area, built up area etc etc are clustered out as an output. Now, I want to use only green/forest area for further coding and since that clustered image, sometimes comes under cluster 1; sometimes under cluster 5/4/3/2; it is impossible to code further.
Can anybody help me in how to avoid random selection of cluster centers in kmeans.
0 Comments
Accepted Answer
Matt Tearle
on 6 Feb 2013
You can do
... = kmeans(...,'start',M);
where M is a matrix of the initial locations of the centers (each row of M is a vector representing the location of one cluster center).
The other alternative would be to post-process -- look at the centroids returned and pick the one that is the most "green".
5 Comments
Matt Tearle
on 8 Feb 2013
Edited: Matt Tearle
on 8 Feb 2013
I'm not an image processing expert, so I don't know exactly, but it seems like your 2-D space is this "a*b* space" (which, according to the link, is red/green vs blue/yellow). But whatever the actual coordinates are, "green" things must live in a cluster somewhere in that space, whereas "white" things would be in a different region. In fact, given that it's 2-D, you could actually plot your data points and the centroids to see what the segmentation looks like:
scatter(ab(:,1),ab(:,2),10,cluster_idx)
hold on
plot(cluster_center(:,1),cluster_center(:,2),'kx','linewidth',3,'markersize',10)
xlabel('red-green'), ylabel('blue-yellow')
(Using the variables created in the demo you linked to.) Now you can see how kmeans is doing the segmentation in a*-b* space.
"White" or "green" or whatever is therefore associated with some region in this space, so whichever centroid is closest to some "canonical" value of "white" is the cluster I would take to be the white group.
For example, if you were working in RGB (rather than a*-b*), I'd take the centroid that was closest to [1,1,1] to be the white cluster, and the one that was closest to [0,1,0] to be green, and so on.
Bottom line: if you have a reasonable idea of the colors that will be selected and, therefore, roughly where the centroids will be, you should be able to map the groups to colors according to the group centroid locations.
EDIT TO ADD: I just reread the link more carefully -- this is basically what they're doing in Step 6. They just say "The blue cluster has the smallest cluster_center value (determined experimentally)" -- so that's the criterion they're using to determine with cluster is "blue".
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!