Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
693 views
in Technique[技术] by (71.8m points)

image processing - rgb to ycbcr conversion in matlab

I am trying to write a function in Matlab that takes an RGB image of class unit8 and double and converts it to a YCBCR image. The transformation formula is below.

The transformation between YCbCr and RGB

I would be really thankful for any help of any kind.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

There's an Image Processing Toolbox function for that, if you have access to it: RGB2YCBCR

If you don't have access to it, here's how you can do the conversion yourself:

rgbImage = imread('peppers.png');  %# A sample RGB image
A = [65.481 -37.797 112; ...       %# A 3-by-3 matrix of scale factors
     128.553 -74.203 -93.786; ...
     24.966 112 -18.214];

%# First convert the RGB image to double precision, scale its values to the
%#   range 0 to 1, reshape it to an N-by-3 matrix, and multiply by A:
ycbcrImage = reshape(double(rgbImage)./255,[],3)*A;

%# Shift each color plane (stored in each column of the N-by-3 matrix):
ycbcrImage(:,1) = ycbcrImage(:,1)+16;
ycbcrImage(:,2) = ycbcrImage(:,2)+128;
ycbcrImage(:,3) = ycbcrImage(:,3)+128;

%# Convert back to type uint8 and reshape to its original size:
ycbcrImage = reshape(uint8(ycbcrImage),size(rgbImage));

And here's the image you get when you display ycbcrImage:

enter image description here


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...