color space plot of image

1 view (last 30 days)
mattia brichetti
mattia brichetti on 13 Jun 2021
Commented: Image Analyst on 13 Jun 2021
in this site
there is a color space plot 2d and 3d in Rcode, how can i plot same graphs in matlab lenguages?
thenks a lot.

Answers (1)

Image Analyst
Image Analyst on 13 Jun 2021
I believe you're wanting the colorcloud() function. It plots the gamut in 3-D. Not sure what a 2-D plot would be. What do the axes represent in 2-D?
  2 Comments
mattia brichetti
mattia brichetti on 13 Jun 2021
wow perfect! Many thanks!
now, if my image is mandrill (same example in link) colorcloud() it works as it should and opens the color space chart to me like in the link, but if i after apply k-means algoritm new plot 3d with colourcloud() print only k(cluster number) point.
what it should do however is plot the color regions, which will be k regions same a plot in link.
I don't think there is a problem in function for k-means implement, i report it below for completeness:
function img_qnt = segment_image(img, k)
img = single(img) ./ 255; %converto il tipo di dato da unit8->single e ne divido le componenti per avere valori "corretti"
[h,w,c] = size(img); %salvo le dimensioni della matrice
I = reshape(img, [], c); %rimodello la matrice img secondo le componenti date
[pixels, colors] = kmeans(I, k, "MaxIter", 100); %implemento l'algoritmo
%pixels è un vettori di indici dei K cluster presenti nella matrice
%colors
I_qnt = I; %copio I, salvandola per modificarla
for pixel = 1:size(I,1) %ciclo sui pixel bidimensionali di I, i.e. 512x512 per effettuare la quantizzazione
I_qnt(pixel, :) = colors(pixels(pixel),:);
end
img_qnt = reshape(I_qnt, h, w, c); %riporto la matrice alle dimensioni originarie
img_qnt = img_qnt .* 255; %necessario per la conversione
img_qnt = uint8(img_qnt); %riconverto i dati nel formato precedente
end
----------------------------------------------------------
for the second queston 2-d plot i think is create with a change of variable, as it says in link, and I wonder if there is already a function that does this or if it needs to be implemented by hand.
thank you very much, very kind!
Image Analyst
Image Analyst on 13 Jun 2021
You can use the view() command to view the colorcloud from a certain vantage point, so that the 3-D cloud appears 2-D.
k-means is usually a poor way of classifying color clusters. I'm attaching my kmeans() demo on a color image as proof. You probably won't use kmeans for color segmentation in real life, but could be fun as an illustrative process - just to see what it does out of curiosity, even though it give lousy results.

Sign in to comment.

Products


Release

R2020b

Community Treasure Hunt

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

Start Hunting!