function encoder
close all; clear;
N = 256;
im = zeros(N,N,3);
im2 = zeros(N,N,3);
Ys = zeros(N,N);
Cbs = zeros(N,N);
Crs = zeros(N,N);
im = makeRGB(im);
subplot(141);
imshow(im);
title("original RGB");
for y=1:N
for x=1:N
R = im(y,x,1);
G = im(y,x,2);
B = im(y,x,3);
[Y,Cb,Cr] = RGB2YCbCR(R,G,B);
im2(y,x,1) = Y;
im2(y,x,2) = Cb;
im2(y,x,3) = Cr;
Ys(y,x) = Y;
Cbs(y,x) = Cb;
Crs(y,x) = Cr;
end
end
subplot(142);
imshow(Ys);
title("Luminance");
subplot(143);
imshow(Cbs);
title("Color diff(Blue)");
subplot(144);
imshow(Crs);
title("Color diff(Red)");
function im=makeRGB(im)
im(1:85,:,1) = 250;
im(86:171,:,2) = 250;
im(172:256,:,3) = 250;
end
function [Y,Cb,Cr] = RGB2YCbCR(R,G,B)
Y = 0.299 * R + 0.587 * G + 0.114 * B - 128;
Cb = - 0.1687 * R - 0.3313 * G + 0.5 * B + 128;
Cr = 0.5 * R - 0.4187 * G - 0.0813 * B + 128;
end
end