K-means (with k=1)?
7 views (last 30 days)
Show older comments
Good day, Is it possible to obtaine 1 cluster setting the minimum input parameter k=1 (k-means) or it starts from k=2 to k=n, where (n - data objects in a given data set) ? (nota bene k-means and some other partitioning algorithms are applicable for k=1...K)? Best regards, TP
3 Comments
Filip
on 12 Feb 2024
I am interested if you got an answer to your question. I ran k-means with k=1 because i need one representative color and I have images of only one percieved color (and possibly multiple shades).
I ran it on all of my images to extract one representative color of all the images.
Is it functionally different from calculating the mean?
Image Analyst
on 12 Feb 2024
@Filip yes he got an answer from me. It's below in the Answers section, you just didn't scroll down far enough. You thought @Adam's comment was an official answer but it's really just a comment up here in the comments section where people ask for clarification of the original question.
You forgot to attach your image. "Shade" is an ambiguous term. You can convert your image into Hue Saturation Value color space. Perhaps you are looking for the dominant hue. In that case just take the histogram of the hue channel and find the mode value.
rgbImage = imread('peppers.png');
subplot(2, 2, 1);
imshow(rgbImage);
hsvImage = rgb2hsv(rgbImage);
hImage = hsvImage(:,:,1);
subplot(2, 2, 2);
imshow(hImage, []);
subplot(2, 2, 3:4);
h = histogram(hImage)
grid on;
[counts, indexOfMax] = max(h.Values)
modeHueValue = h.BinEdges(indexOfMax)
You can see it says the dominant color value is the purple. This is not the same as taking the mean of all the values.
If you have any more questions, then attach your images with the paperclip icon after you read this:
Answers (1)
Image Analyst
on 10 Mar 2017
A k of one means that there is only one cluster in your data set - in other words every element in your data belongs to the same cluster. There is no point in even running kmeans() in that case.
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!