% 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

B41 = double( I41(:, :, 3) );

B42 = double( I42(:, :, 3) );

B43 = double( I43(:, :, 3) );

B44 = double( I44(:, :, 3) );

B45 = double( I45(:, :, 3) );


B46 = double( I46(:, :, 3) );


Noise_B42 = B42 - B41;


Noise_B43 = B43 - B41;


Noise_B44 = B44 - B41;

Noise_B45 = B45 - B41;


Noise_B46 = B46 - B41;


% Large Area Signal to Noise Ratio

incremental_gain = 0.1;
maximum_level = 255;

% Blue component
sumNB42 = 0;
sumNB43 = 0;
sumNB44 = 0;
sumNB45 = 0;
sumNB46 = 0;

for counter1 = 1: 1: M
   for counter2 = 1: 1: N
      sumNB42 = sumNB42 + Noise_B42(counter1, counter2) * Noise_B42(counter1, counter2);
      sumNB43 = sumNB43 + Noise_B43(counter1, counter2) * Noise_B43(counter1, counter2);
      sumNB44 = sumNB44 + Noise_B44(counter1, counter2) * Noise_B44(counter1, counter2);
      sumNB45 = sumNB45 + Noise_B45(counter1, counter2) * Noise_B45(counter1, counter2);
      sumNB46 = sumNB46 + Noise_B46(counter1, counter2) * Noise_B46(counter1, counter2);

   end;
end;

sumNB42 = sumNB42 / ( M * N );
sumNB43 = sumNB43 / ( M * N );
sumNB44 = sumNB44 / ( M * N );
sumNB45 = sumNB45 / ( M * N );
sumNB46 = sumNB46 / ( M * N );


AVG_totalNB42 = sqrt( sumNB42 );
AVG_totalNB43 = sqrt( sumNB43 );
AVG_totalNB44 = sqrt( sumNB44 );
AVG_totalNB45 = sqrt( sumNB45 );
AVG_totalNB46 = sqrt( sumNB46 );


SNR_B42 = maximum_level * 0.18 / ( AVG_totalNB42 * incremental_gain );
SNR_B43 = maximum_level * 0.18 / ( AVG_totalNB43 * incremental_gain );
SNR_B44 = maximum_level * 0.18 / ( AVG_totalNB44 * incremental_gain );
SNR_B45 = maximum_level * 0.18 / ( AVG_totalNB45 * incremental_gain );
SNR_B46 = maximum_level * 0.18 / ( AVG_totalNB46 * incremental_gain );

SNR_B = [  SNR_B42 SNR_B43 SNR_B44 SNR_B45 SNR_B46 ]


figure(1);
subplot(2, 1, 1);
plot(SNR_B );
title(' Large Area Signal to Noise Ratio Blue component ' );
grid;
subplot( 2, 1, 2);
bar( SNR_B );
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;










