MATLAB: How to define a color

colorcolor segmentationcolourImage Processing Toolboxselecting

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.

Best Answer

Oh yeah, It's crystal clear now!
So, for instance the color you want to pick is black and you just want to define it.
I took a look at your question again. ginput gives you the x and y in respect to x and y axes, for images, ginput returns the pixel number (pixel 0 0 is on the top and left of the image) so it does not provide any color info on it's own.
You can use the result of the ginput to get the color though. Depending on the type of the image you're loading to MATLAB, you'll have different data types, lets say you loaded a colored image of type PNG. then you'll have a (Xpixel x Ypixelcdata x 3) cdata (color data) matrix. 3rd dimension is 3, representing the red, green and blue and they're uint8 type, means the're in between 0 to 255.
So let's say you want to red color. then
myPic(1,1,1:3) = [255,0,0]
myPic(1,2,1:3) = [0,255,0]
myPic(1,3,1:3) = [0,0,255]
to define a color for your purpose I believe you've to do it as such
color = [255,100,44] % whatever color it is!
Just combine the three colors with with different amounts and produce what ever color you want.
If you want to cheat from the image, just use ginput to get the x and y coordinates of the desired pixel then in the cdata matrix or whatever matrix you named it, I named it myPic, get the color values to understand their mixture.
mypic(x,y,:)
Hope this can answer your question, sorry I got back to you a bit late.
Good Luck!
Related Question