本文介绍了rgb到matlab中的ycbcr转换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试在Matlab中编写一个函数,该函数采用类unit8和double的RGB图像并将其转换为YCBCR图像。转换公式如下。
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.
我会非常感谢任何帮助。
I would be really thankful for any help of any kind.
推荐答案
如果你有权访问它,有一个功能:
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));
这是显示 ycbcrImage :
这篇关于rgb到matlab中的ycbcr转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!