Ask Your Question
0

HowTo split YCrCb into Y, Cr and Cb?

asked 2014-05-13 02:30:18 -0600

StudentFeM gravatar image

Hi,

I've created an Mat Object and split it into three channels:


vector<mat> bgr_planes;
split(frame, bgr_planes);
The content in the Mat frame is:

frame = {Cr0, Y0, Cb0, Y1, Cr2, Y3, Cb2, Y4, Cr4, Y5, Cr4, ...}
How can I separate the Y, Cb and Cr component?

Is there a function?

Best regards, Michael

edit retag flag offensive close merge delete

Comments

1

A loop over the image is the only way of retrieving individual pixels ...

StevenPuttemans gravatar imageStevenPuttemans ( 2014-05-13 02:39:03 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2014-05-13 05:02:50 -0600

Y Simson gravatar image

Why don't you convert the image first into YCbCr and then use split?

Mat YCbCr;
cvtColor(frame, YCbCr, COLOR_BGR2YCrCb);

vector<mat> ycbcr_planes;
split(frame, ycbcr_planes);
edit flag offensive delete link more

Comments

2

sorry, but look at the question again. his input is not rgb, but interleaved ycrcb

berak gravatar imageberak ( 2014-05-13 05:27:58 -0600 )edit

Is it stored as type CV_8UC3 ? In this case split is exactly what you need. In OpenCV the multi channel data is stored in interleaved format by default. See this tutorial.

I take your correction regarding the color conversion. You are correct that it won't be needed.

Y Simson gravatar imageY Simson ( 2014-05-13 07:00:25 -0600 )edit

unfortunately it's not really CV_8UC3. interleaved means, that for every pixel, there's 2 bytes, the Y (intensity) component, and alternating cr (odd) or cb(even).

berak gravatar imageberak ( 2014-05-13 07:07:14 -0600 )edit

I understand. This is YUV422 format. For every pixel of Luma(Y) you have one Chroma alternating between CbCr.

What you need to to do is first separate Luma from Chroma. Then split the two Chroma channels.

Then upsample by x2 the Chroma Channels horizontally, to turn them into the same size as as the Luma (presuming this is what you want).

Y Simson gravatar imageY Simson ( 2014-05-13 07:50:00 -0600 )edit

Another option I can offer is to convert this YUV422 Image which is actually in YV12 format into RGB then Split it.

Or split it after converting back to YCbCr 4:4:4 format.

Mat YUV444, GRB;
vector&lt;Mat&gt; SplitYCbCr;

cvtColor(frame, GRB, COLOR_YUV2BGR_UYVY);
cvtColor(GRB, YUV444, COLOR_BGR2YCrCb);

split(YUV444, SplitYCbCr);

Note: When upsampling the Chroma channels you need to pay attention whether source is video of Jpeg image. Both use 422 formats widely but define them differently.

Y Simson gravatar imageY Simson ( 2014-05-13 09:13:45 -0600 )edit

Question Tools

Stats

Asked: 2014-05-13 02:30:18 -0600

Seen: 9,700 times

Last updated: May 13 '14