This code implemented a comparison between “k-means” “mean-shift” and “normalized-cut” segmentation
Teste methods are:
Kmeans segmentation using (color) only
Kmeans segmentation using (color + spatial)
Mean Shift segmentation using (color) only
Mean Shift segmentation using (color + spatial)
Normalized Cut (inherently uses spatial data)
kmeans parameter is "K" that is Cluster Numbers
meanshift parameter is "bw" that is Mean Shift Bandwidth
ncut parameters are "SI" Color similarity, "SX" Spatial similarity, "r" Spatial threshold (less than r pixels apart), "sNcut" The smallest Ncut value (threshold) to keep partitioning, and "sArea" The smallest size of area (threshold) to be accepted as a segment
an implementation by "Naotoshi Seo" with a little modification is used for “normalized-cut” segmentation, available online at: "http://note.sonots.com/SciSoftware/NcutImageSegmentation.html". It is sensitive in choosing parameters.
an implementation by "Bryan Feldman" is used for “mean-shift clustering"
Alireza (2020). k-means, mean-shift and normalized-cut segmentation (https://www.mathworks.com/matlabcentral/fileexchange/52698-k-means-mean-shift-and-normalized-cut-segmentation), MATLAB Central File Exchange. Retrieved .
Thanks a lot for the code. Is there any chance that you have this code for 3d Point cloud as well?
Thanks for your code. I would like to ask how can we get locations of cluster's centroid after mean shift segmentation.
hello , thank you for your code
please ,what must i add to this code if i want to show the centroid of clusters in the image ?
Good, easy to read and use.
what is the significance of this bound box you are calculating, it has no use for further implementation?
@Alireza...Hello thank you for this code...Can you plz tell me..will this work for grayscale images. I run this code on gray image but it doesnot work..it shows error:
Error using reshape
To RESHAPE the number of elements must not change.
Error in Km (line 5)
F = reshape(I,size(I,1)*size(I,2),3); % Color Features
How can i use this method for gray image? Plz help me..
First off, thank you for posting this.
Secondly, I'd like to point out that when using spatial and color information as features you're normalizing the spatial information by performing:
L = [y(:)/max(y(:)),x(:)/max(x(:))];
Which is by itself a very valid operation if you want to introduce spatial information to some normalized features-space.
But my problem is that no such normalization is done on the color channels:
C = reshape(I,size(I,1)*size(I,2),3);
And I would like to suggest an improvement when using color information, use the L*a*b* color space:
lab_I = rgb2lab(I);
C = reshape(lab_I(:,:,2:3)./max(max(lab_I(:,:,2:3))),size(I,1)*size(I,2),2);
In this code, there is an array of cluster votes at the end of all iterations (when all pixels are associated with some cluster).
ClusterVotes has pixels as columns and clusters as rows where values are votes for each cluster for a given pixel. The author then associate pixel with that cluster with which it has more votes.
Now, I can't understand this thing.
For example, say the pixel has 10 votes for cluster 1 and 3 votes for cluster 2.
By author's logic, pixel will be associated to cluster 1.
But maybe the 10 votes that are associated to cluster 1 was given at the start of iterations and this pixel went out of bandwidth near to end of iterations.
Similarly, maybe the cluster 2 got its 3 votes near the end of mean-shift iterations that is when this pixel was indeed in the bandwidth and when mean stopped shifting.
So in such cases pixel should be associated to cluster 2.
how can we convert the Km2 to work with intensity instead of color?
@Luu Thanh, the current implementations are not the most efficient ones. They have rather used to proof concepts.
is any citation for this code (K-Means color+spatial) etc.
I got the the ff problem when I run the code.
Error using matlab.graphics.axis.Axes/set
There is no Style property on the Axes class.
I am using R2015b..
@Luu. Although K-means is faster, it only gives spherical shaped clusters. Mean shift is more robust compared to K-means as it does not assume any shape of clusters, see paper by Comaniciu and Meer for more details.
Best image segmentation ever
hello Sir, I hear that K-mean (O(kn)) is faster than MeanShift (O(kn*n)). So why when I used your algorithm, MeanShift alway run faster ? Thank you !
FX submission added
Inspired by: K-means clustering