% Calculate the mean and Standard Deviation of the images for each R, G, B components
% Pictures processed by Ofoto company

clear;
% load the image


Ofoto41 = imread('ofoto41.jpg', 'jpg');
Ofoto42 = imread('ofoto42.jpg', 'jpg');
Ofoto43 = imread('ofoto43.jpg', 'jpg');
Ofoto44 = imread('ofoto44.jpg', 'jpg');
Ofoto45 = imread('ofoto45.jpg', 'jpg');

% Noise analysis 1. Compute the mean and Standard deviation

[ M, N ] = size( Ofoto41(:, :, 1) );

% Statistical data of the images

% RGB mean values
AvgOfoto41_R = mean2( Ofoto41(:, :, 1) );
AvgOfoto41_G = mean2( Ofoto41(:, :, 2) );
AvgOfoto41_B = mean2( Ofoto41(:, :, 3) );

AvgOfoto42_R = mean2( Ofoto42(:, :, 1) );
AvgOfoto42_G = mean2( Ofoto42(:, :, 2) );
AvgOfoto42_B = mean2( Ofoto42(:, :, 3) );

AvgOfoto43_R = mean2( Ofoto43(:, :, 1) );
AvgOfoto43_G = mean2( Ofoto43(:, :, 2) );
AvgOfoto43_B = mean2( Ofoto43(:, :, 3) );

AvgOfoto44_R = mean2( Ofoto44(:, :, 1) );
AvgOfoto44_G = mean2( Ofoto44(:, :, 2) );
AvgOfoto44_B = mean2( Ofoto44(:, :, 3) );

AvgOfoto45_R = mean2( Ofoto45(:, :, 1) );
AvgOfoto45_G = mean2( Ofoto45(:, :, 2) );
AvgOfoto45_B = mean2( Ofoto45(:, :, 3) );


AVG_R = [ AvgOfoto41_R AvgOfoto42_R AvgOfoto43_R AvgOfoto44_R AvgOfoto45_R ]
AVG_G = [ AvgOfoto41_G AvgOfoto42_G AvgOfoto43_G AvgOfoto44_G AvgOfoto45_G ]
AVG_B = [ AvgOfoto41_B AvgOfoto42_B AvgOfoto43_B AvgOfoto44_B AvgOfoto45_B ]

figure(1);
subplot(3,1, 1);
bar(AVG_R );
title(' Histogram of the Average values of Red vs. Noise ');
grid;
subplot(3,1, 2);
bar(AVG_G );
title(' Histogram of the Average values of Green vs. Noise');
grid;
subplot(3, 1,3);
bar( AVG_B);
title(' Histogram of the Average values of Blue vs. Noise');
xlabel(' Noise ');
grid;

% Standard Deviation of the noise

stdOfoto41_R = std2( Ofoto41(:, :, 1) );
stdOfoto41_G = std2( Ofoto41(:, :, 2) );
stdOfoto41_B = std2( Ofoto41(:, :, 3) );

stdOfoto42_R = std2( Ofoto42(:, :, 1) );
stdOfoto42_G = std2( Ofoto42(:, :, 2) );
stdOfoto42_B = std2( Ofoto42(:, :, 3) );

stdOfoto43_R = std2( Ofoto43(:, :, 1) );
stdOfoto43_G = std2( Ofoto43(:, :, 2) );
stdOfoto43_B = std2( Ofoto43(:, :, 3) );

stdOfoto44_R = std2( Ofoto44(:, :, 1) );
stdOfoto44_G = std2( Ofoto44(:, :, 2) );
stdOfoto44_B = std2( Ofoto44(:, :, 3) );

stdOfoto45_R = std2( Ofoto45(:, :, 1) );
stdOfoto45_G = std2( Ofoto45(:, :, 2) );
stdOfoto45_B = std2( Ofoto45(:, :, 3) );


STD_R = [ stdOfoto41_R stdOfoto42_R stdOfoto43_R stdOfoto44_R stdOfoto45_R  ]
STD_G = [ stdOfoto41_G stdOfoto42_G stdOfoto43_G stdOfoto44_G stdOfoto45_G  ]
STD_B = [ stdOfoto41_B stdOfoto42_B stdOfoto43_B stdOfoto44_B stdOfoto45_B  ]



figure(2);
subplot( 3,1,1);
bar( STD_R);
title(' Histogram of Standard Deviation of Red vs. Noise');
grid;
subplot(3, 1, 2);
bar( STD_G );
title('Histogram of Standard Deviation of Green vs. Noise');
grid;
subplot(3, 1, 3);
bar( STD_B );
title(' Histogram of Standard Deviation of Blue vs. Noise ');
grid;

figure(3);
subplot(3,1,1);
plot( Ofoto41(1, :, 1) );
title(' Original Image ');
grid;
subplot(3,1,2);
plot( Ofoto42(1, :, 1) );
title(' Image with Gaussian Noise variance = 0.02 ');
grid;
subplot(3,1,3);
plot( Ofoto43(1, :, 1) );
title(' Image with Gaussian Noise variance = 0.05 ');
grid;

figure(4);
subplot(2,1,1);
plot( Ofoto44(1, :, 1) );
title(' Image with Gaussian Noise variance = 0.1 ');
grid;
subplot(2,1,2);
plot( Ofoto45(1, :, 1) );
title(' Image with Gaussian Noise variance = 0.2 ');
grid;
