% Compute the SNR ratio of the digital image
% Shutterfly pictures

clear;
% load the image

I41 = imread('access41.jpg', 'jpg');
I42 = imread('access42.jpg', 'jpg');
I43 = imread('access43.jpg', 'jpg');
I44 = imread('access44.jpg', 'jpg');
I45 = imread('access45.jpg', 'jpg');
I46 = imread('access46.jpg', 'jpg');


% find out the dimension
[ M, N ] = size( I41(:, :, 1) );

% Isolate the R, G, B, components

R41 = double( I41(:, :, 1) );

R42 = double( I42(:, :, 1) );

R43 = double( I43(:, :, 1) );

R44 = double( I44(:, :, 1) );
R45 = double( I45(:, :, 1) );
R46 = double( I46(:, :, 1) );

Noise_R42 = R42 - R41;
Noise_R43 = R43 - R41;


Noise_R44 = R44 - R41;


Noise_R45 = R45 - R41;


Noise_R46 = R46 - R41;


% Large Area Signal to Noise Ratio

incremental_gain = 0.1;
maximum_level = 255;

% Red component
sumNR42 = 0;
sumNR43 = 0;
sumNR44 = 0;
sumNR45 = 0;
sumNR46 = 0;

for counter1 = 1: 1: M
   for counter2 = 1: 1: N
      sumNR42 = sumNR42 + Noise_R42(counter1, counter2) * Noise_R42(counter1, counter2);
      sumNR43 = sumNR43 + Noise_R43(counter1, counter2) * Noise_R43(counter1, counter2);
      sumNR44 = sumNR44 + Noise_R44(counter1, counter2) * Noise_R44(counter1, counter2);
      sumNR45 = sumNR45 + Noise_R45(counter1, counter2) * Noise_R45(counter1, counter2);
      sumNR46 = sumNR46 + Noise_R46(counter1, counter2) * Noise_R46(counter1, counter2);
   end;
end;

sumNR42 = sumNR42 / ( M * N );
sumNR43 = sumNR43 / ( M * N );
sumNR44 = sumNR44 / ( M * N );
sumNR45 = sumNR45 / ( M * N );
sumNR46 = sumNR46 / ( M * N );


sumNR42 = sqrt( sumNR42 );
sumNR43 = sqrt( sumNR43 );
sumNR44 = sqrt( sumNR44 );
sumNR45 = sqrt( sumNR45 );
sumNR46 = sqrt( sumNR46 );


SNR_R42 = maximum_level * 0.18 / ( sumNR42 * incremental_gain );
SNR_R43 = maximum_level * 0.18 / ( sumNR43 * incremental_gain );
SNR_R44 = maximum_level * 0.18 / ( sumNR44 * incremental_gain );
SNR_R45 = maximum_level * 0.18 / ( sumNR45 * incremental_gain );
SNR_R46 = maximum_level * 0.18 / ( sumNR46 * incremental_gain );

SNR_R = [  SNR_R42 SNR_R43 SNR_R44 SNR_R45 SNR_R46 ] 


figure(1);
subplot(2, 1, 1);
plot(SNR_R );
title(' Large Area Signal to Noise Ratio Red component ' );
grid;
subplot( 2, 1, 2);
bar( SNR_R );
title(' Bar garph ');
grid;





% Fixed pattern Signal to Noise Ratio


%Fix_SNR_R41 = maximum_level * 0.18 / ( Avg_fix_NR41 * incremental_gain );
%Fix_SNR_R42 = maximum_level * 0.18 / ( Avg_fix_NR42 * incremental_gain );
%Fix_SNR_R43 = maximum_level * 0.18 / ( Avg_fix_NR43 * incremental_gain );
%Fix_SNR_R44 = maximum_level * 0.18 / ( Avg_fix_NR44 * incremental_gain );
%Fix_SNR_R45 = maximum_level * 0.18 / ( Avg_fix_NR45 * incremental_gain );
%Fix_SNR_R46 = maximum_level * 0.18 / ( Avg_fix_NR46 * incremental_gain );

%Fix_SNR_R = [ Fix_SNR_R41 Fix_SNR_R42 Fix_SNR_R43 Fix_SNR_R44 Fix_SNR_R45 Fix_SNR_R46 ];
%figure(4);
%subplot(2, 1, 1);
%plot( Fix_SNR_R );
%title(' Fixed Pattern Signal to Noise Ratio -- Red  Shutterfly ');
%grid;
%subplot(2, 1, 2 );
%bar( Fix_SNR_R );
%grid;










