1 仿真
仿真通过vga驱动读入图片,首先经过rgb2ycbcr444算法再到ycbcr444转ycbcr422算法再到ycbcr422转ycbcr444算法最后ycbcr444再转会rgb真彩色图像,整个过程如下图所示。
2 fpga实现
fpga的实现采用hdmi输入,dvi转rgb后验证过程与仿真实现过程一致,最后通过rgb转dvi输出到hdmi口。整个过程如下图所示。
3 视频演示
3.1 rgb2ycbcr444视频效果
原文阅读:YCbCr444转YCbCr422
3.2 ycbcr444转422视频效果
原文阅读:fpga实现YCbCr422转YCbCr444
3.3 ycbcr422转ycbcr444视频效果
4 matlab整体验证
代码语言:javascript复制close all
clear all
clc
I=imread('1.bmp');
[H ,W ,D]=size(I);
R=double(I(:,:,1));
G=double(I(:,:,2));
B=double(I(:,:,3));
% Y0= double(zeros(H,W));
% Cb0 =double(zeros(H,W));
% Cr0 = double(zeros(H,W));
for i = 1:H
for j = 1:W
Y0(i, j) = 0.299*R(i, j) 0.587*G(i, j) 0.114*B(i, j);
Cb0(i, j) = -0.172*R(i, j) - 0.339*G(i, j) 0.511*B(i, j) 128;
Cr0(i, j) = 0.511*R(i, j) - 0.428*G(i, j) - 0.083*B(i, j) 128;
end
end
Iycbcr(:,:,1)=Y0;
Iycbcr(:,:,2)=Cb0;
Iycbcr(:,:,3)=Cr0;
Iycbcr=uint8(Iycbcr);
% imshow(Iycbcr);
% Iycbcr=rgb2ycbcr(I);
% Y0=Iycbcr(:,:,1);
% Cb0=Iycbcr(:,:,2);
% Cr0=Iycbcr(:,:,3);
%
%
for i=1:1:H
for j=2:2:W
Cb1(i,j/2)=(Cb0(i,j-1) Cb0(i,j))/2;
end
end
for i=1:1:H
for j=2:2:W
Cr1(i,j/2)=(Cr0(i,j-1) Cr0(i,j))/2;
end
end
for i=1:1:H
for j=1:1:W
if rem(j,2)==0
CbCr(i,j)=Cr1(i,j/2);
else
CbCr(i,j)=Cb1(i,(j 1)/2);
end
end
end
for i=1:1:H
for j=1:1:W
if rem(j,2)==0
Cb(i,j)=Cb1(i,j/2);
else
Cb(i,j)=Cb1(i,(j 1)/2);
end
end
end
for i=1:1:H
for j=1:1:W
if rem(j,2)==0
Cr(i,j)=Cr1(i,j/2);
else
Cr(i,j)=Cr1(i,(j 1)/2);
end
end
end
YCbCr(:,:,1)=Y0;
YCbCr(:,:,2)=Cb;
YCbCr(:,:,3)=Cr;
YCbCr=uint8(YCbCr);
for i = 1:H
for j = 1:W
rgb(i, j,1) =Y0(i,j) 1.371*(Cr(i,j)-128);
rgb(i, j,2) =Y0(i,j)-0.689*(Cr(i,j)-128)-0.336*(Cb(i,j)-128);
rgb(i, j,3) =Y0(i,j) 1.732*(Cb(i,j)-128);
end
end
rgb=uint8(rgb);
imshow(rgb);
Y0=uint8(Y0);
Cb0=uint8(Cb0);
Cr0=uint8(Cr0);
Cb1=uint8(Cb1);
Cr1=uint8(Cr1);
CbCr=uint8(CbCr);
Cb=uint8(Cb);
Cr=uint8(Cr);
% rgb=ycbcr2rgb(YCbCr);
%
figure(1),
imshow(I);
figure(2),
subplot(221),imshow(Iycbcr);
subplot(222),imshow(Y0);
subplot(223),imshow(Cb0);
subplot(224),imshow(Cr0);
figure(3),
subplot(221),imshow(Cb1);
subplot(222),imshow(Cr1);
subplot(223),imshow(CbCr);
figure(4),
subplot(221),imshow(Cb);
subplot(222),imshow(Cr);
subplot(223),imshow(YCbCr);
figure(5),
subplot(221),imshow(Iycbcr);
subplot(222),imshow(YCbCr);
subplot(223),imshow(rgb);
imwrite(CbCr,'CbCr.jpg');