How do I define a color?
Mostrar comentarios más antiguos
Hi,
I am carrying out an image segmentation and during this I define colour as the specific colour I need segmented by clicking on the image itself. However, is it possible for me to put in that colour is equal to a specific colour?
[x, y] = ginput(1);
color=imLabel(floor(y),floor(x),:);
This is basically the code I use and then it gives me the option to pick the spot I want and it defines it as that color. Is there a function I can use to define it as the color permanently, without needing me to pick it every time.
Thanks.
2 comentarios
Salaheddin Hosseinzadeh
el 21 de Ag. de 2014
Editada: Salaheddin Hosseinzadeh
el 21 de Ag. de 2014
Hi
What do you mean you want a permanent color?!
Just define color as
color = [.5 1 1];
if you don't want to pick a point!!!
I don't think if I understood your question!
How about explaining a bit more? Tell us what's the application of the "color" vector? Where you gonna use that? Possibly in a plot command?!
Tnx
msij
el 22 de Ag. de 2014
Respuesta aceptada
Más respuestas (1)
Image Analyst
el 25 de Ag. de 2014
If you want to count that one particular, specific color, just define it and find it.
myColor = [142, 129, 204]; % Or whatever you want.
% Find the red color
binaryRed = rgbImage(:,:,1) == myColor(1);
% Find the green color
binaryGreen = rgbIage(:,:,1) == myColor(2);
% Find the blue color
binaryBlue = rgbImage(:,:,1) == myColor(3);
% Count how many times it matches all 3 color channels anywhere in the image.
thatColor = binaryRed & binaryGreen & binaryBlue; % 2d binary map of where this color lives
countForThatColor = sum(thatColor(:)); % Sum up to do the counting.
If you want to do it for more than just one color and want to do it for the whole image (every color in the image), then you want the "color frequency image" and that code is given here: http://www.mathworks.com/matlabcentral/fileexchange/28164-color-frequency-image It has interesting visualizations.
In addition, see my File Exchange http://www.mathworks.com/matlabcentral/fileexchange/?term=authorid%3A31862, particularly the delta E one where it finds colors similar to the color you specify.
Categorías
Más información sobre Images en Centro de ayuda y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!