K-means (with k=1)?

7 Ansichten (letzte 30 Tage)
Taras Panskyi
Taras Panskyi am 10 Mär. 2017
Kommentiert: Image Analyst am 12 Feb. 2024
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 Kommentare
Filip
Filip am 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
Image Analyst am 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.
Like @Adam and I said, a k of 1 is just all the data.
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)
h =
Histogram with properties: Data: [384x512 double] Values: [11862 4677 5065 5603 7890 6479 7173 8306 7479 4473 2728 1532 638 179 78 38 41 19 32 33 41 19 14 3 1 35 6 4 2 12 10 8 2 49 12 21 54 231 2853 ... ] (1x50 double) NumBins: 50 BinEdges: [0 0.0200 0.0400 0.0600 0.0800 0.1000 0.1200 0.1400 0.1600 0.1800 0.2000 0.2200 0.2400 0.2600 0.2800 0.3000 0.3200 0.3400 0.3600 0.3800 0.4000 ... ] (1x51 double) BinWidth: 0.0200 BinLimits: [0 1] Normalization: 'count' FaceColor: 'auto' EdgeColor: [0 0 0] Use GET to show all properties
grid on;
[counts, indexOfMax] = max(h.Values)
counts = 34632
indexOfMax = 42
modeHueValue = h.BinEdges(indexOfMax)
modeHueValue = 0.8200
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:
But post it in a new discussion thread, not here in @Taras Panskyi's question.

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Image Analyst
Image Analyst am 10 Mär. 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.

Community Treasure Hunt

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

Start Hunting!

Translated by