RGB通道和YCBCR通道相互转换——MATLAB实现
Posted 实在人dx
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了RGB通道和YCBCR通道相互转换——MATLAB实现相关的知识,希望对你有一定的参考价值。
YCBCR2RGB.m
% addpath(genpath(pwd)); %将当前文件夹下的所有文件夹都包括进调用函数的目录
% clc,clear;
function [ycbcr_img] = YCBCR2RGB(Y,Cb,Cr)
[w,h] = size(Y);
ycbcr_img = zeros(w,h,3);
ycbcr_img(:,:,1) = Y+1.402*(Cr-128/255.0);
ycbcr_img(:,:,2) = Y-0.344*(Cb-128/255.0)-0.714*(Cr-128/255.0);
ycbcr_img(:,:,3) = Y+1.772*(Cb-128/255.0);
end
RGB2YCBCR.m
% clc,clear;
function [Y,Cb,Cr,img_ycbcr] = RGB2YCBCR(RGB_image)
% RGB_image = im2double(imread('./MRI_SPECT/SPETCT/SPECT.png'));
R = RGB_image(:,:,1);
G = RGB_image(:,:,2);
B = RGB_image(:,:,3);
Y = 0.299 * R + 0.587 * G + 0.114 * B;
Cb = -0.1687 * R - 0.3313 * G + 0.5 * B + 128/255.0;
Cr = 0.5 * R - 0.4187 * G - 0.0813 * B + 128/255.0;
[w,h,~] = size(RGB_image);
img_ycbcr = zeros(w,h,3);
img_ycbcr(:,:,1) = Y;
img_ycbcr(:,:,2) = Cb;
img_ycbcr(:,:,3) = Cr;
end
以上是关于RGB通道和YCBCR通道相互转换——MATLAB实现的主要内容,如果未能解决你的问题,请参考以下文章