% This code has two main applications.  The first is to find the difference in noise added by the printing process.                    
% A graph is created that shows the noises added to the fft domain by printing and scanning.       
%
% Also, this code creates a graph of the human visual system that finds the optimal frequencies that can be changed for data encoding!



glsized = imread('gasleaksized.tif');
glscnsized = imread('300dpi_gasleaksized.tif');


presamp = glsized;
postsamp = glscnsized(1:762,1:1211);

prefft = fft2(double(presamp))/(mean(mean(fft2(double(presamp)))));
postfft = fft2(double(postsamp))/(mean(mean(fft2(double(presamp)))));

S = size(prefft);
I = S(1);
J = S(2);

r = 0.7;
aT = 0.649;
fmin = 3.68;
Tmin = 1.1548;
K = 1.728;

for i = 1:I,
   fi0 = prefft(i,1);
   for j = 1:J,
      f0j = prefft(1,j);

		T(i,j) = exp(log(Tmin*(fi0^2 + f0j^2)^2/((fi0^2 + f0j^2)^2 - 4*(1 - r)*fi0^2*f0j^2)) + K*(log(sqrt(fi0^2 + f0j^2)) - log(fmin))^2);
   end
end

T(1,1) = T(1,2);
figure;
mesh(abs(T));
figure;


error = prefft - postfft;
mesh(log(abs(error)));


