%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Multimedia  %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Contenuti:  - LETTURA DI IMMAGINI
%             - CONVERSIONE IN TONI DI GRIGIO
%             - Resizing IMMAGINI
%             - CONVERSIONE NELLO SPAZIO YCbCr
%             - 

close all % chiude tutte le finestre
clear all % pulisce la memoria di Matlab

clear
imread('citta.jpg');
subplot(2,2,1);
f=imread('citta.jpg');
imshow(f);
flipped=f(end:-1:1, :, :);
subplot(2,2,2);
imshow(flipped);
cropped=f(60:300, 60:420,:);
subplot(2,2,3);
imshow(cropped);
subplot(2,2,4);
plot(f(:,10,1));

a=imread('kodim23.png');
figure;imshow(a);
[M,N,I]=size(a)
b=uint8(zeros(M,N,I));

RED=a(:,:,1);
GREEN=a(:,:,2);
BLUE=a(:,:,3);

b(:,:,1)=BLUE;
b(:,:,2)=RED;
b(:,:,3)=GREEN;
b=uint8(b);
figure;imshow(b);

a_reduced=imresize(a,0.5,'bilinear');

a_zoomed1=imresize(a_reduced,2,'nearest');
a_zoomed2=imresize(a_reduced,2,'bilinear');
a_zoomed3=imresize(a_reduced,2,'bicubic');

figure;imshow(a);
figure;imshow(a_zoomed1);
figure;imshow(a_zoomed2);
figure;imshow(a_zoomed3);

a_gray=rgb2gray(a);
imshow(a_gray);

a_YCbCr=rgb2ycbcr(a);
Y=a_YCbCr(:,:,1);
Cb=a_YCbCr(:,:,2);
Cr=a_YCbCr(:,:,3);

imshow(Y)
figure;imshow(Cb)
Cb_reduced=imresize(Cb,.5,'bicubic');
Cr_reduced=imresize(Cr,.5,'bicubic');
figure;imshow(Cb_reduced);
Cb_enlarged=imresize(Cb_reduced,2,'bicubic');
Cr_enlarged=imresize(Cr_reduced,2,'bicubic');

a_new_YCbCr(:,:,1)=Y;
a_new_YCbCr(:,:,2)=Cb_enlarged;
a_new_YCbCr(:,:,3)=Cr_enlarged;

a_rgb=ycbcr2rgb(a_new_YCbCr);
figure;imshow(a_rgb);
figure;imshow(a);
Diff=mean(abs(a(:)-a_rgb(:)))
