Ask Your Question
0

OpenCv: extract the Y component from Ycrcb to form a grayscale image

asked 2014-08-06 03:33:19 -0600

cv_new gravatar image

updated 2014-08-06 03:33:46 -0600

I'd like to do some processing from the RGB image to the YUV image. And then store the Y component into a grayscale Mat. How can I do it? Thanks in advance!!!

The following is the code in Matlab

function [] = ycctest(imageName)

rgb = imread(imageName);

ycbcr = rgb2ycbcr(rgb);   %convert to yuv space

%display the y component as a color image

ycbcry = ycbcr;

ycbcry(:,:,2) = 0;

ycbcry(:,:,3) = 0;

rgb1 = ycbcr2rgb(ycbcry);

gray = rgb2gray(rgb1);

figure, imshow(gray );

end

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
2

answered 2014-08-06 03:42:45 -0600

berak gravatar image

updated 2014-08-06 03:48:54 -0600

here's split:

Mat bgr = imread("my.png"); 

Mat ycbcr;
cvtColor(bgr,ycbcr,CV_BGR2YCBCR);

Mat chan[3];
split(ycbcr,chan);

Mat y  = chan[0];
Mat cb = chan[1];
Mat cr = chan[2];
edit flag offensive delete link more

Comments

It works, Thanks

cv_new gravatar imagecv_new ( 2014-08-06 04:07:40 -0600 )edit

Question Tools

Stats

Asked: 2014-08-06 03:33:19 -0600

Seen: 10,816 times

Last updated: Aug 06 '14