function [imout,fir]=defocus(in,harsh,rv)

%		[imout,fir]=defocus(in,harsh,rv)
%	defocus takes a happy little crisp sharp image IN and unfocuses it
%	a HARSH amount (between 1 and 10) and with a random RV (1-100)
%	amount of deviance from a normal gaussian distribution.

x=[0:1/20:.05*harsh];
for(i=1:size(x,2)) xa(i)=x(size(x,2)-i+1); end;
sxa=size(xa,2);

xa(2*sxa-1)=0;
xa(sxa:2*sxa-1)=x;

a=pdf('Normal',xa,0,(.05*harsh^(.5)));
aa=a'*a;

%figure, imagesc(aa)

%random blur component:

ab=aa.*(1 + (rv^2/(sqrt(harsh)*20)*rand(size(aa))));
fir=ab/sum(sum(ab));

% figure , imagesc(fir)
% input('doh')

%fft's:

sin=2*max(size(in));
sfir=2*max(size(fir));

IN=fft2(in,sin,sin);
FIR=fft2(fir,sin,sin);

%ifft's: 

OUT=IN.*FIR;
outnot=ifft2(OUT);
imout=abs(outnot);

