function [g,h] = degrade(f,P,K,b)
%DIP Classroom DEmo
%Shreekanth Mandayam, Rowan University 
%Function degrades a clean image by simulating 
%blur due to atmospheric turbulence
%Inputs:
%f: original image matrix
%P: Size of point spread function
%K: Strength of point spread function
%b: Spread of the blur factor
%h: point spread function
%Outputs:
%g: degraded image matrix
%h: point spread function matrix
%Generating PSF

clear h; close all; 
center=ceil(P/2);
for i=1:P;
   for j=1:P;
      i1=i-center;
      j1=j-center; 
      h(i,j)=K*exp(-(0.5*i1^2/b^2 + 0.5*j1^2/b^2));
   end;
end;

%Degrading the original image 
g=filter2(h,f);

%Displaying results
figure(1); imshow(mat2gray(f)); title('f: Original'); 
figure(2); imshow(mat2gray(g));title('g: Degraded'); 
figure(3);imshow(mat2gray(h), 'InitialMagnification','fit');title('h: PSF');
