Ask Your Question

HowTo split YCrCb into Y, Cr and Cb?

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

StudentFeM gravatar image


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



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

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

1 answer

Sort by ยป oldest newest most voted

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

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



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

berak gravatar imageberak ( 2014-05-13 05:27:58 -0500 )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 -0500 )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 -0500 )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 -0500 )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 -0500 )edit
Login/Signup to Answer

Question Tools


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

Seen: 6,394 times

Last updated: May 13 '14