Glo*_*ove 1 matlab image-processing image-conversion
我正在尝试在Matlab中编写一个函数,该函数采用类unit8的RGB图像并将其转换为YCBCR图像.转换公式如下.

我会非常感谢任何帮助.
如果您可以访问它,则有一个图像处理工具箱功能:RGB2YCBCR
如果您无权访问它,请按照以下方式进行转换:
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));
Run Code Online (Sandbox Code Playgroud)
这是您显示时获得的图像ycbcrImage:
