RGB values in a YUV colorspace image

I have an image in YUV colorspace and when i preview it using imshow() function,the image shows RGB values at each pixel but when i type img_name(x,y,:) in the workspace,it shows some other values. So how do i get those RGB values which are shown in the figure using the imshow() function in the workspace or use them for further processing.

 Réponse acceptée

Image Analyst
Image Analyst le 30 Juin 2015

0 votes

How did you get that image in that color space? Was it from a camera?
Also, the value is different from workspace (variable editor) to what you type in because you typed in the wrong thing. You typed in img_name(x,y,:) instead of img_name(y, x, :). Remember, with matrices the ROW is the first index, not the column.

6 commentaires

nitin
nitin le 30 Juin 2015
yes,i got that YUV image from the webcam. and what i mean is that the value of a particular pixel is different from the one using the imshow function,for eg. if i make a YUV image using img_name(:,:,1) (the first component) and view it using imshow function,it shows RGB values which are all the same and when i try to get the same value in workspace for a particular pixel,i get a different value(which is its index value).
Can you set your video mode to RGB? If not, then you might have one of those cameras that doesn't have an RGB mode. All is not lost though. There is an option of videoinput() that lets you set the returned video mode to convert it into an RGB image. Check out this link by David Tarkowski, the developer of this toolbox at the Mathworks: http://www.mathworks.com/matlabcentral/answers/5634#answer_8178
vid = videoinput('winvideo', 1);
set(vid, 'ReturnedColorSpace', 'RGB');
img = getsnapshot(vid);
imshow(img)
nitin
nitin le 30 Juin 2015
yes i can set the colorspace to RGB but the work i am trying to do is more accurate in YUV especially if i get the img(:,:,1) component of the YUV image.The image uploading shows the difference between the index and the RGB values,when i access the first component of the YUV image,i only get the index in workspace not the RGB value
Image Analyst
Image Analyst le 30 Juin 2015
I'm not sure I buy your argument about YUV being more accurate. Do you have any justification for that? Anyway, your images are of such poor quality yet high contrast that you could probably use any color space to find the arm and hand. I don't think accuracy will be required. I mean, who cares if the edge of the arm is off by one pixel? Is that going to make a difference in determining if the person held up fingers in a "V" or an "O" shape? No.
Simple thresholding is not sufficient to find all colors of skin in any color space. Why not? Because the gamut of skin colors cannot be "boxed in" by such thresholds because it is a boomerang or banana shape. It's curved. Have you ever seen it? You'd need to define multiple threshold "zones" to "carve out" the boomerang shape from the gamut.
Anyway, the values in MATLAB are accurate. It's just your interpretation that off. For example thinking row,column is x,y or thinking RGB is YUV. Any image you display is considered RGB and if you use the data cursor or impixelinfo() to read out the values, it will give you the values as a triplet but they are the values of whatever you displayed. For example if you pass an YUV image to imshow() it will not convert the image but show the Y image as red, the U image as G and the V image as B. I think using impixel() or impixelinfo() on that will give you the values of the underlying matrix, not the screen RGB values. To get the RGB values, you'd have to transform back to RGB space. I'm not sure I see any discrepancy in the image you uploaded.
nitin
nitin le 30 Juin 2015
when i convert the image in YUV space most of the pixels values img(:,:,2) and img(:,:,3) goes to zero for that particular image and in this case only,so it provides me a more convenient option to scan and manipulate the image.
Image Analyst
Image Analyst le 30 Juin 2015
That's because you have a neutral background. The S channel of an HSV image, and the A and B channels of an LAB color space image would also have very small values. I have several color classification tutorials/demos in my File Exchange: http://www.mathworks.com/matlabcentral/fileexchange/?term=authorid%3A31862 that you can adapt to get the arm.

Connectez-vous pour commenter.

Plus de réponses (2)

Thorsten
Thorsten le 30 Juin 2015
Modifié(e) : Thorsten le 30 Juin 2015

0 votes

imshow treats the image as an RGB image. If it is not, e.g., if some values are negative, these values are set to 0. Note that if you click on some point in the image shown by imshow, RGB values are shown. But these are just the YUV values from your original image mapped to whatever imshow considers to be an appropriate range, (e.g., negative values are mapped to 0). To use these values for further processing would mean that you want to process the data on the peculiar scalings done by the imshow function. I doubt that this is what you want. If you need rgb values, you have to convert the YUV image to RGB.

7 commentaires

nitin
nitin le 30 Juin 2015
yes,i am trying to access those values which are mapped by the imshow function for further use in my code. Is there any way to use those values?
Thorsten
Thorsten le 30 Juin 2015
I think you have to find out the operation that imshow applies to the data and then apply these operation on your data.
BTW, I do not understand why you use imshow for YUV. It should be displayed in false colors, and I do not understand why you want to apply the operation performed by imshow (which regard the image as if it were an RGB image) for your YUV image.
nitin
nitin le 30 Juin 2015
i am trying to detect skin in my image and when i view the YUV colorspace image using the imshow function,the RGB values are different from the background i am using.
Thorsten
Thorsten le 30 Juin 2015
I see. I think it's best if you provide the image such that we can have a closer look.
nitin
nitin le 30 Juin 2015
here is the image using what i get img(:,:,1) and img is in YUV colorspace,i am trying to segment the hand using the different values of the skin of img(:,:,1) then the background but in the workspace i dont get the RGB values(which i get from the imshow) but the index of the pixel
Thorsten
Thorsten le 30 Juin 2015
Please also post the original image.
nitin
nitin le 30 Juin 2015
here are the two images,RGB and YUV

Connectez-vous pour commenter.

Walter Roberson
Walter Roberson le 30 Juin 2015

0 votes

The others have explained why what you ask is probably not what you need. The way to do as you ask is to get the File Exchange contribution freezeColors(), apply it to the the displayed image, and then get() the CData property of the image() object.

Catégories

Community Treasure Hunt

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

Start Hunting!

Translated by