RGB 与 (RGB转 YCbCr再转为 RGB)的图像

2018/02/20 20:53
阅读数 33

       RGB 与 (RGB转 YCbCr再转为 RGB)的图像   不可逆,能够从 矩阵的逆运算看出来。

附上 matlab 代码:

       

clc,clear;
Source=imread('1.jpg');%读入原始RGB图像

figure(1);
subplot(1,2,1);
imshow(Source):title('original image');%显示图像
[r c d]=size(Source);%计算图像大小
%------计算红色分量并显示分解图------%
R(:,:,1)=Source(:,:,1);
R(:,:,2)=zeros(r,c);
R(:,:,3)=zeros(r,c);
R=uint8(R);
whos;
figure(2);
subplot(1,3,1);
imshow(R)
title('Red Component');
%-------计算绿色分量并显示分解图-------%
G(:,:,2)=Source(:,:,2);
G(:,:,1)=zeros(r,c);
G(:,:,3)=zeros(r,c);
G=uint8(G);
figure(2);
subplot(1,3,2);
imshow(G)
title('Green Component');
%--------计算蓝色分量并显示分解图-------%
B(:,:,3)=Source(:,:,3);
B(:,:,1)=zeros(r,c);
B(:,:,2)=zeros(r,c);
B=uint8(B);
figure(2);
subplot(1,3,3)
imshow(B)
title('Blue Component');
%------------合成-------------%
Comp(:,:,1)=R(:,:,1);
Comp(:,:,2)=G(:,:,2);
Comp(:,:,3)=B(:,:,3);
figure(5);
subplot(1,2,2);
imshow(Comp):title('composition image');
Y=0.213*R+0.715*G+0.072*B;
Cb=0.511*B-0.117*R-0.394*G+128;
Cr=0.511*R-0.464*G-0.047*B+128;
%red=Y+1.402*(Cr-128);
%green=Y-0.34414*(Cb-128)-0.71414*(Cr-128);
%blue=Y+1.772*(Cb-128);
red = 1.164*(Y-16)+1.793*(Cr-128);
green = 1.164*(Y-16)-0.534*(Cr-128)-0.213*(Cb-128);
blue =1.164*(Y-16)+2.115*(Cb-128);
Comp2(:,:,1)=red(:,:,1);
Comp2(:,:,2)=green(:,:,2);
Comp2(:,:,3)=blue(:,:,3);
Comp5(:,:,1)=Y(:,:,1);
Comp5(:,:,2)=Cb(:,:,2);
Comp5(:,:,3)=Cr(:,:,3);
figure(5);imshow(Comp5);title('显示11YCBcr');
figure(1);subplot(1,2,2);imshow(Comp2);title('RGB转换为YCrCb后又转换为RGB的图像');
RD=R(:,:,1)-red(:,:,1);
GD=G(:,:,2)-green(:,:,2);
BD=B(:,:,3)-blue(:,:,3);
figure(4);subplot(1,3,1);imshow(RD);title('红色分量差异');
subplot(1,3,2);imshow(GD);title('绿色分量差异');
subplot(1,3,3);imshow(BD);title('蓝色分量差异');

展开阅读全文
red
打赏
0
0 收藏
分享
加载中
更多评论
打赏
0 评论
0 收藏
0
分享
返回顶部
顶部