% gives cos^4 falloff gain image to divide each input image by

function gain=input_principaldistance_in_millimeters(M,N,mm_f);

if nargin<2
  error('cos4: need at least 2 input arguments (desired size of output image)')
end%if

if nargin<3
  disp('cos4: lens focal length defaulting to 7.5mm')
  mm_f=7.5                  % known focal length of lens but principal dist more
end%if

[n,m]=meshgrid(1:N,1:M);
disp('for now, setting center to be at actual center')
m0=M/2+1/2;
n0=N/2+1/2;

mm_diag=2.54*10*(1/2)     % diagonal size of sensor array
mm_radius=mm_diag/2       % circumscribing circle
pixels_radius=sqrt((M/2)^2+(N/2)^2);
pixelspermm=pixels_radius/mm_radius
f=mm_f*pixelspermm

one=ones(M,N);
r_squared=(m-one*m0).^2+(n-one*n0).^2;
gain=(one*(f^2)./(r_squared+one*(f^2))).^2;  % cos^4(theta); where theta = arccos(f/R)

