Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

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

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

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

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