码迷,mamicode.com
首页 > 其他好文 > 详细

RGB转换成YCbCr

时间:2017-10-30 18:21:43      阅读:492      评论:0      收藏:0      [点我收藏+]

标签:orb   mat   col   imshow   UI   double   read   ble   end   

clear all;
close all;
clc;

img=imread(‘colorbar.jpg‘);%(‘ngc6543a.jpg‘);
%img=mat2gray(img);  %[0,1];
[m n dim]=size(img);
imshow(img);
%picture RGB
img=double(img);
R=img(:,:,1);
G=img(:,:,2);
B=img(:,:,3);

%%RGB2YCbCr
Y=zeros(m,n);    %
Cb=zeros(m,n);   
Cr=zeros(m,n);   
matrix=[0.299 0.587 0.114;
        -0.172 -0.339 0.511;
        0.511 -0.428 -0.083];
for i=1:m
   for j=1:n 
        tmp=matrix*[R(i,j) G(i,j) B(i,j)]‘;
        Y(i,j)=tmp(1);
        Cb(i,j)=tmp(2)+128;
        Cr(i,j)=tmp(3)+128;
   end
end

%%YCbCr2RGB
matrix=inv(matrix);
for i=1:m
   for j=1:n 
        tmp=matrix*[Y(i,j) Cb(i,j)-128 Cr(i,j)-128]‘;
        R(i,j)=tmp(1);
        G(i,j)=tmp(2);
        B(i,j)=tmp(3);
   end
end

%%
img(:,:,1)=R;
img(:,:,2)=G;
img(:,:,3)=B;
figure;
imshow(uint8(img))

  

RGB转换成YCbCr

标签:orb   mat   col   imshow   UI   double   read   ble   end   

原文地址:http://www.cnblogs.com/zhongguo135/p/7755300.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!