Ask Your Question
0

Understanding YUV to BGR color spaces conversion

asked 2015-03-20 09:23:18 -0600

begueradj gravatar image

I read a BGR image:

bgr=cv2.imread('bgr.png')

I convert it to YUV color space:

yuv=cv2.cvtColor(bgr,cv2.COLOR_BGR2YUV)

Now I set U and V values of yuv image to 0:

for i in range(yuv.shape[0]):
    for j in range(yuv.shape[1]):
         yuv[i,j,1]=0
         yuv[i,j,2]=0

Now I convert yuv to BGR and display it:

BGR=cv2.cvtColor(yuv,cv2.COLOR_YUV2BGR)
cv2.imshow('BGR',BGR)

The problem is that BGR is displayed totally green (Blue and Red channels are always 0 on all the pixels)

Does this mean that Y in YUV color space is saved as G in BGR when we convert an image from YUV to BGR colorspaces ?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
3

answered 2015-03-20 09:35:31 -0600

updated 2015-03-20 09:37:26 -0600

No. The connection between The RGB and the YUV color space is:

image description

So when you have YUV(0,0,0) in RGB you have : 0,135,0

That is coming from the definition of the YUV color space.

http://www.mikekohn.net/file_formats/...

http://en.wikipedia.org/wiki/YUV

http://softpixel.com/~cwright/program...

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2015-03-20 09:23:18 -0600

Seen: 17,518 times

Last updated: Mar 20 '15