Ask Your Question
0

Differences between Gray to YUV conversion (CvtColor VS Create a Mat with Y component)

asked 2018-02-12 04:10:47 -0600

isra60 gravatar image

AFAIK , A YUV image from Gray8 image is just copy the Gray8 image data to the Y-component. Meaning that the crominances are 0 value.

Based on this

https://en.wikipedia.org/wiki/YUV#/me...

So if I have a gray8 Mat (heightwidth) my YUV Mat result is a Mat(1.5height * width) So I just create a Mat with the first (heightwidth) bytes to Y and the rest of bytes just to 0 values.

But when I tried to use cvtColor Conversion; First Gray->BGR and then BGR->YUV420 (cvtcolor does not have direct conversion) my result Mat is a Mat(1.5height * width), but the last values of each frame (the crominances) are 128 not 0-values...

I don't understand this difference but it seems the second one (created with cvtcolor) is the correct one. My own created Mat from the gray8 data results on a Green Image...

Any hints??

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
2

answered 2018-12-07 02:36:28 -0600

isra60 gravatar image

Maybe a little late... but the conversion is like this..

Y = (0.257 * R) + (0.504 * G) + (0.098 * B) + 16

Cr = V = (0.439 * R) - (0.368 * G) - (0.071 * B) + 128

Cb = U = -(0.148 * R) - (0.291 * G) + (0.439 * B) + 128

Basically a greyscale image in bgr format repeats the component of grayscale three times to create a 3 channel image, so in order to convert from a grey8 image to YUV

Y = grayValue + 16

Cr = V = 128

Cb = U = 128

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2018-02-12 04:10:47 -0600

Seen: 2,078 times

Last updated: Dec 07 '18