Assigning word to different colour

I have a code using k means
for k = 1:(length(dirlist))
img = imread([pathname, dirlist(k).name]);
flatImg = double(reshape(img,size(img,1)*size(img,2),size(img,3)));
idx = kmeans(flatImg,3);
end
I have around 20 images ,I have specified k=3,so for each colour i need to specify a word such as A,B,C
please tell how toprocess

5 comentarios

Walter Roberson
Walter Roberson el 31 de Ag. de 2012
What "word" are you referring to in your question, that is to be assigned a different color?
kash
kash el 31 de Ag. de 2012
words aor letters such as
A for one colour
B for another colour
C for another colour
kash
kash el 31 de Ag. de 2012
for example the output of idx will consists of 1's,2's,3's
so want to assign A for 1
B for 2
C for 3
Walter Roberson
Walter Roberson el 31 de Ag. de 2012
The output of idx is not colors, it is cluster numbers.
Image Analyst
Image Analyst el 31 de Ag. de 2012
Why do you want to do this? Why not just turn it back into an image? What are you going to do with a character array?

Respuestas (1)

Walter Roberson
Walter Roberson el 31 de Ag. de 2012
cluster_letter = char('A' + idx - 1);

1 comentario

kash
kash el 1 de Sept. de 2012
Editada: Walter Roberson el 1 de Sept. de 2012
i did the following
for k = 1:(length(dirlist))
img = imread([pathname, dirlist(k).name]);
flatImg = double(reshape(img,size(img,1)*size(img,2),size(img,3)));
idx = kmeans(flatImg,3);
N{k}=(reshape(idx,size(img,1),size(img,2)))
cluster_letter = char('A' + idx - 1)
Ncluster{k}=(reshape(cluster_letter,size(img,1),size(img,2)))
end
i get the answer, but in variable editor i get all values in same cell ,i need each letter in each cell

La pregunta está cerrada.

Etiquetas

Preguntada:

el 31 de Ag. de 2012

Cerrada:

el 20 de Ag. de 2021

Community Treasure Hunt

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

Start Hunting!

Translated by