# Understanding YUV to BGR color spaces conversion

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 close merge delete

Sort by ยป oldest newest most voted

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

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...

more

Official site

GitHub

Wiki

Documentation

## Stats

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

Seen: 15,254 times

Last updated: Mar 20 '15