RGB转换成YCbCr

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))

  

上一篇:《Entity Framework 6 Recipes》中文翻译系列 (18) -----第三章 查询之结果集扁平化和多属性分组


下一篇:10. Regular Expression Matching[H]正则表达式匹配