% One-dimensional Signal Analysis for each R, G, B components
% 

clear;
% load the image

Fly41 = imread('ofoto41.jpg', 'jpg');
Fly42 = imread('ofoto42.jpg', 'jpg');
Fly43 = imread('ofoto43.jpg', 'jpg');
Fly44 = imread('ofoto44.jpg', 'jpg');
Fly45 = imread('ofoto45.jpg', 'jpg');

% Noise analysis 1. Compute the mean and Standard deviation

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

% Statistical data of the images
SigR41 = double( Fly41(100, 600:1800, 1) );
SigR42 = double( Fly42(100, 600:1800, 1) );
SigR43 = double( Fly43(100, 600:1800, 1) );
SigR44 = double( Fly44(100, 600:1800, 1) );
SigR45 = double( Fly45(100, 600:1800, 1) );

SigG41 = double( Fly41(100, 600:1800, 2) );
SigG42 = double( Fly42(100, 600:1800, 2) );
SigG43 = double( Fly43(100, 600:1800, 2) );
SigG44 = double( Fly44(100, 600:1800, 2) );
SigG45 = double( Fly45(100, 600:1800, 2) );

SigB41 = double( Fly41(100, 600:1800, 3) );
SigB42 = double( Fly42(100, 600:1800, 3) );
SigB43 = double( Fly43(100, 600:1800, 3) );
SigB44 = double( Fly44(100, 600:1800, 3) );
SigB45 = double( Fly45(100, 600:1800, 3) );

AvgR41 = mean( SigR41);
AvgR42 = mean( SigR42);
AvgR43 = mean( SigR43);
AvgR44 = mean( SigR44);
AvgR45 = mean( SigR45);

AvgG41 = mean( SigG41);
AvgG42 = mean( SigG42);
AvgG43 = mean( SigG43);
AvgG44 = mean( SigG44);
AvgG45 = mean( SigG45);

AvgB41 = mean( SigB41);
AvgB42 = mean( SigB42);
AvgB43 = mean( SigB43);
AvgB44 = mean( SigB44);
AvgB45 = mean( SigB45);

DevR41 = std( SigR41);
DevR42 = std( SigR42);
DevR43 = std( SigR43);
DevR44 = std( SigR44);
DevR45 = std( SigR45);

DevG41 = std( SigG41);
DevG42 = std( SigG42);
DevG43 = std( SigG43);
DevG44 = std( SigG44);
DevG45 = std( SigG45);

DevB41 = std( SigB41);
DevB42 = std( SigB42);
DevB43 = std( SigB43);
DevB44 = std( SigB44);
DevB45 = std( SigB45);

% Define SNR (signal to noise ratio ) as mean / STD
SNRR41 = AvgR41 / DevR41;
SNRR42 = AvgR42 / DevR42;
SNRR43 = AvgR43 / DevR43;
SNRR44 = AvgR44 / DevR44;
SNRR45 = AvgR45 / DevR45;

SNRG41 = AvgG41 / DevG41;
SNRG42 = AvgG42 / DevG42;
SNRG43 = AvgG43 / DevG43;
SNRG44 = AvgG44 / DevG44;
SNRG45 = AvgG45 / DevG45;

SNRB41 = AvgB41 / DevB41;
SNRB42 = AvgB42 / DevB42;
SNRB43 = AvgB43 / DevB43;
SNRB44 = AvgB44 / DevB44;
SNRB45 = AvgB45 / DevB45;

SNRR = [ SNRR41 SNRR42 SNRR43 SNRR44 SNRR45  ]
SNRG = [ SNRG41 SNRG42 SNRG43 SNRG44 SNRG45 ]
SNRB = [ SNRB41 SNRB42 SNRB43 SNRB44 SNRB45  ]

AverageR = [ AvgR41 AvgR42 AvgR43 AvgR44 AvgR45 ];
AverageG = [ AvgG41 AvgG42 AvgG43 AvgG44 AvgG45  ];
AverageB = [ AvgB41 AvgB42 AvgB43 AvgB44 AvgB45  ];

StandardR = [ DevR41 DevR42 DevR43 DevR44 DevR45  ];
StandardG = [ DevG41 DevG42 DevG43 DevG44 DevG45 ];
StandardB = [ DevB41 DevB42 DevB43 DevB44 DevB45  ];



% About the center of the image
figure(1);
subplot(3,1,1);
plot( Fly41(600, :, 1) );
title(' Image with no noise Red signal around the center');
grid;
subplot(3,1,2);
plot( Fly42(600, :, 1) );
title(' Image with Gaussian Noise variance = 0.02 ');
grid;
subplot(3,1,3);
plot( Fly43(600, :, 1) );
title(' Image with Gaussian Noise variance = 0.05 ');
grid;

figure(2);
subplot(2,1,1);
plot( Fly44(600, :, 1) );
title(' Image with Gaussian Noise variance = 0.1  Red component');
grid;
subplot(2,1,2);
plot( Fly45(600, :, 1) );
title(' Image with Gaussian Noise variance = 0.2 ');
grid;

figure(3);
subplot(3,1,1);
plot( Fly41(600, :, 2) );
title(' Image with no noise  Green component around center signal');
grid;
subplot(3,1,2);
plot( Fly42(600, :, 2) );
title(' Image with Gaussian Noise variance = 0.02 ');
grid;
subplot(3,1,3);
plot( Fly43(600, :, 2) );
title(' Image with Gaussian Noise variance = 0.05 ');
grid;

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

figure(5);
subplot(3,1,1);
plot( Fly41(600, :, 3) );
title(' Image with no noise  Blue component around center signal');
grid;
subplot(3,1,2);
plot( Fly42(600, :, 3) );
title(' Image with Gaussian Noise variance = 0.02 ');
grid;
subplot(3,1,3);
plot( Fly43(600, :, 3) );
title(' Image with Gaussian Noise variance = 0.05 ');
grid;

figure(6);
subplot(2,1,1);
plot( Fly44(600, :, 3) );
title(' Image with Gaussian Noise variance = 0.1  Blue component around center signal');
grid;
subplot(2,1,2);
plot( Fly45(600, :, 3) );
title(' Image with Gaussian Noise variance = 0.2 ');
grid;



% About the edge of the image
figure(7);
subplot(3,1,1);
plot( Fly41(10, :, 1) );
title(' Image with no noise  Red signal around the edge');
grid;
subplot(3,1,2);
plot( Fly42(10, :, 1) );
title(' Image with Gaussian Noise variance = 0.02 ');
grid;
subplot(3,1,3);
plot( Fly43(10, :, 1) );
title(' Image with Gaussian Noise variance = 0.05 ');
grid;

figure(8);
subplot(3,1,1);
plot( Fly44(10, :, 1) );
title(' Image with Gaussian Noise variance = 0.1  Red component around the edge');
grid;
subplot(3,1,2);
plot( Fly45(10, :, 1) );
title(' Image with Gaussian Noise variance = 0.2 ');
grid;

figure(9);
subplot(3,1,1);
plot( Fly41(10, :, 2) );
title(' Image with no noise  Green component around the edge');
grid;
subplot(3,1,2);
plot( Fly42(10, :, 2) );
title(' Image with Gaussian Noise variance = 0.02 ');
grid;
subplot(3,1,3);
plot( Fly43(10, :, 2) );
title(' Image with Gaussian Noise variance = 0.05 ');
grid;

figure(10);
subplot(3,1,1);
plot( Fly44(10, :, 2) );
title(' Image with Gaussian Noise variance = 0.1  Green component around the edge');
grid;
subplot(3,1,2);
plot( Fly45(10, :, 2) );
title(' Image with Gaussian Noise variance = 0.2 ');
grid;

figure(11);
subplot(3,1,1);
plot( Fly41(10, :, 3) );
title(' Image with no noise  Blue component around the edge');
grid;
subplot(3,1,2);
plot( Fly42(10, :, 3) );
title(' Image with Gaussian Noise variance = 0.02 ');
grid;
subplot(3,1,3);
plot( Fly43(10, :, 3) );
title(' Image with Gaussian Noise variance = 0.05 ');
grid;

figure(12);
subplot(3,1,1);
plot( Fly44(10, :, 3) );
title(' Image with Gaussian Noise variance = 0.1  Blue component around the edge');
grid;
subplot(3,1,2);
plot( Fly45(10, :, 3) );
title(' Image with Gaussian Noise variance = 0.2 ');
grid;

figure(13);
subplot( 3, 1, 1);
bar( AverageR );
title(' One- Dimensional Signal average vs. Noise Red Component ');
grid;
subplot(3, 1, 2);
bar(AverageG );
title(' One- Dimensional Signal average vs. Noise Green Component ');
grid;
subplot(3,1,3);
bar(AverageB);
title(' One- Dimensional Signal average vs. Noise Blue Component ');
grid;

figure(14);
subplot( 3, 1, 1);
bar( StandardR );
title(' One- Dimensional Signal STD vs. Noise Red Component ');
grid;
subplot(3, 1, 2);
bar(StandardG );
title(' One- Dimensional Signal STD vs. Noise Green Component ');
grid;
subplot(3,1,3);
bar(StandardB);
title(' One- Dimensional Signal STD vs. Noise Blue Component ');
grid;

figure(15);
subplot(3,1,1);
bar(SNRR);
title(' Signal to Noise Ratio vs. Noise for Red Component ');
grid;
subplot(3 ,1, 2);
bar(SNRG);
title(' Signal to Noise Ratio vs. Noise for Green Component ');
grid;
subplot(3, 1, 3);
bar( SNRB);
title(' Signal to Noise Ratio vs. Noise for Blue component ');
grid;
