% Calculate the mean and Standard Deviation of the images for each R, G, B components
% 

clear;
% load the image


Original41 = imread('original41.jpg', 'jpg');
Original42 = imread('original42.jpg', 'jpg');
Original43 = imread('original43.jpg', 'jpg');
Original44 = imread('original44.jpg', 'jpg');
Original45 = imread('original45.jpg', 'jpg');
Original46 = imread('original46.jpg', 'jpg');

% Noise analysis 1. Compute the mean and Standard deviation

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

% Statistical data of the images

% RGB mean values
AvgOriginal41_R = mean2( Original41(:, :, 1) );
AvgOriginal41_G = mean2( Original41(:, :, 2) );
AvgOriginal41_B = mean2( Original41(:, :, 3) );

AvgOriginal42_R = mean2( Original42(:, :, 1) );
AvgOriginal42_G = mean2( Original42(:, :, 2) );
AvgOriginal42_B = mean2( Original42(:, :, 3) );

AvgOriginal43_R = mean2( Original43(:, :, 1) );
AvgOriginal43_G = mean2( Original43(:, :, 2) );
AvgOriginal43_B = mean2( Original43(:, :, 3) );

AvgOriginal44_R = mean2( Original44(:, :, 1) );
AvgOriginal44_G = mean2( Original44(:, :, 2) );
AvgOriginal44_B = mean2( Original44(:, :, 3) );

AvgOriginal45_R = mean2( Original45(:, :, 1) );
AvgOriginal45_G = mean2( Original45(:, :, 2) );
AvgOriginal45_B = mean2( Original45(:, :, 3) );

AvgOriginal46_R = mean2( Original46(:, :, 1) );
AvgOriginal46_G = mean2( Original46(:, :, 2) );
AvgOriginal46_B = mean2( Original46(:, :, 3) );


AVG_R = [ AvgOriginal41_R AvgOriginal42_R AvgOriginal43_R AvgOriginal44_R AvgOriginal45_R AvgOriginal46_R  ]
AVG_G = [ AvgOriginal41_G AvgOriginal42_G AvgOriginal43_G AvgOriginal44_G AvgOriginal45_G AvgOriginal46_G ]
AVG_B = [ AvgOriginal41_B AvgOriginal42_B AvgOriginal43_B AvgOriginal44_B AvgOriginal45_B AvgOriginal46_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
stdOriginal41_R = std2( Original41(:, :, 1) );
stdOriginal41_G = std2( Original41(:, :, 2) );
stdOriginal41_B = std2( Original41(:, :, 3) );

stdOriginal42_R = std2( Original42(:, :, 1) );
stdOriginal42_G = std2( Original42(:, :, 2) );
stdOriginal42_B = std2( Original42(:, :, 3) );

stdOriginal43_R = std2( Original43(:, :, 1) );
stdOriginal43_G = std2( Original43(:, :, 2) );
stdOriginal43_B = std2( Original43(:, :, 3) );

stdOriginal44_R = std2( Original44(:, :, 1) );
stdOriginal44_G = std2( Original44(:, :, 2) );
stdOriginal44_B = std2( Original44(:, :, 3) );

stdOriginal45_R = std2( Original45(:, :, 1) );
stdOriginal45_G = std2( Original45(:, :, 2) );
stdOriginal45_B = std2( Original45(:, :, 3) );

stdOriginal46_R = std2( Original46(:, :, 1) );
stdOriginal46_G = std2( Original46(:, :, 2) );
stdOriginal46_B = std2( Original46(:, :, 3) );

STD_R = [ stdOriginal41_R stdOriginal42_R stdOriginal43_R stdOriginal44_R stdOriginal45_R stdOriginal46_R ]
STD_G = [ stdOriginal41_G stdOriginal42_G stdOriginal43_G stdOriginal44_G stdOriginal45_G stdOriginal46_G ]
STD_B = [ stdOriginal41_B stdOriginal42_B stdOriginal43_B stdOriginal44_B stdOriginal45_B stdOriginal46_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( Original41(1, :, 1) );
title(' Original Image ');
grid;
subplot(3,1,2);
plot( Original42(1, :, 1) );
title(' Image with Gaussian Noise variance = 0.02 ');
grid;
subplot(3,1,3);
plot( Original43(1, :, 1) );
title(' Image with Gaussian Noise variance = 0.05 ');
grid;

figure(4);
subplot(3,1,1);
plot( Original44(1, :, 1) );
title(' Image with Gaussian Noise variance = 0.1 ');
grid;
subplot(3,1,2);
plot( Original45(1, :, 1) );
title(' Image with Gaussian Noise variance = 0.2 ');
grid;
subplot(3,1,3);
plot( Original46(1, :, 1) );
title(' Image with Gaussian Noise variance = 0.5 ');
grid;


