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

clear;
% load the image


Fly41 = imread('fly41A.jpg', 'jpg');
Fly42 = imread('fly42.jpg', 'jpg');
Fly43 = imread('fly43.jpg', 'jpg');
Fly44 = imread('fly44.jpg', 'jpg');
Fly45 = imread('fly45.jpg', 'jpg');
Fly46 = imread('fly46.jpg', 'jpg');

% Noise analysis 1. Compute the mean and Standard deviation

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

% Statistical data of the images

% RGB mean values
AvgFly41_R = mean2( Fly41(:, :, 1) );
AvgFly41_G = mean2( Fly41(:, :, 2) );
AvgFly41_B = mean2( Fly41(:, :, 3) );

AvgFly42_R = mean2( Fly42(:, :, 1) );
AvgFly42_G = mean2( Fly42(:, :, 2) );
AvgFly42_B = mean2( Fly42(:, :, 3) );

AvgFly43_R = mean2( Fly43(:, :, 1) );
AvgFly43_G = mean2( Fly43(:, :, 2) );
AvgFly43_B = mean2( Fly43(:, :, 3) );

AvgFly44_R = mean2( Fly44(:, :, 1) );
AvgFly44_G = mean2( Fly44(:, :, 2) );
AvgFly44_B = mean2( Fly44(:, :, 3) );

AvgFly45_R = mean2( Fly45(:, :, 1) );
AvgFly45_G = mean2( Fly45(:, :, 2) );
AvgFly45_B = mean2( Fly45(:, :, 3) );

AvgFly46_R = mean2( Fly46(:, :, 1) );
AvgFly46_G = mean2( Fly46(:, :, 2) );
AvgFly46_B = mean2( Fly46(:, :, 3) );


AVG_R = [ AvgFly41_R AvgFly42_R AvgFly43_R AvgFly44_R AvgFly45_R AvgFly46_R  ]
AVG_G = [ AvgFly41_G AvgFly42_G AvgFly43_G AvgFly44_G AvgFly45_G AvgFly46_G ]
AVG_B = [ AvgFly41_B AvgFly42_B AvgFly43_B AvgFly44_B AvgFly45_B AvgFly46_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
stdFly41_R = std2( Fly41(:, :, 1) );
stdFly41_G = std2( Fly41(:, :, 2) );
stdFly41_B = std2( Fly41(:, :, 3) );

stdFly42_R = std2( Fly42(:, :, 1) );
stdFly42_G = std2( Fly42(:, :, 2) );
stdFly42_B = std2( Fly42(:, :, 3) );

stdFly43_R = std2( Fly43(:, :, 1) );
stdFly43_G = std2( Fly43(:, :, 2) );
stdFly43_B = std2( Fly43(:, :, 3) );

stdFly44_R = std2( Fly44(:, :, 1) );
stdFly44_G = std2( Fly44(:, :, 2) );
stdFly44_B = std2( Fly44(:, :, 3) );

stdFly45_R = std2( Fly45(:, :, 1) );
stdFly45_G = std2( Fly45(:, :, 2) );
stdFly45_B = std2( Fly45(:, :, 3) );

stdFly46_R = std2( Fly46(:, :, 1) );
stdFly46_G = std2( Fly46(:, :, 2) );
stdFly46_B = std2( Fly46(:, :, 3) );

STD_R = [ stdFly41_R stdFly42_R stdFly43_R stdFly44_R stdFly45_R stdFly46_R ]
STD_G = [ stdFly41_G stdFly42_G stdFly43_G stdFly44_G stdFly45_G stdFly46_G ]
STD_B = [ stdFly41_B stdFly42_B stdFly43_B stdFly44_B stdFly45_B stdFly46_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( Fly41(1, :, 1) );
title(' Original Image ');
grid;
subplot(3,1,2);
plot( Fly42(1, :, 1) );
title(' Image with Gaussian Noise variance = 0.02 ');
grid;
subplot(3,1,3);
plot( Fly43(1, :, 1) );
title(' Image with Gaussian Noise variance = 0.05 ');
grid;

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

