function p = radon(a,theta,n)
%RADON	Radon transform.
%	The radon transform of an image is the projected sum of 
%	the intensity at a given angle.
%
%	P = RADON(I,THETA) returns the radon transform of the 
%	intensity image I for the angle THETA degrees.  The result
%	P contains the projected sum of the image intensity as
%	a vector.  If THETA is a vector, then P contains the
%	radon transform for the angles in THETA as columns.
%	P will have MAX(SIZE(I)) rows.
%
%	P = RADON(I,THETA,N) returns the radon transform with
%	N points.

%	Clay M. Thompson 2-23-93
%	Copyright (c) 1993 by The MathWorks, Inc.
%	$Revision: 1.7 $  $Date: 1993/09/01 19:49:13 $

error(nargchk(2,3,nargin));

if nargin<3, n = max(size(a)); end

[f1,f2] = freqspace(n);

% Transform image to Fourier domain
aa = fftshift(fft2(a,n,n));

% Create interpolation points for each value in theta
theta = theta(:)'*pi/180; % Convert to radians.
xi = f1'*cos(theta);
yi = f2'*sin(theta);

% Interpolate in column blocks
blk = bestblk(size(xi),min(size(xi,1)/10,100));
m = floor(size(xi,2)/blk(2));
pp = zeros(size(xi));
for i=1:m
  cols = (1:blk(2))+(i-1)*blk(2);
  % Interpolate to find fourier transform of p.
  pp(:,cols) = interp4(f1,f2,aa,xi(:,cols),yi(:,cols));
end
if size(xi,2)/blk(2)>m,
  cols = blk(2)*m+1:size(xi,2);
  % Interpolate to find fourier transform of p.
  pp(:,cols) = interp4(f1,f2,aa,xi(:,cols),yi(:,cols));
end
d = find(isnan(pp)); if ~isempty(d), pp(d) = zeros(size(d)); end

% Inverse 1-D fftshift
n1 = 1:floor(n/2);
n2 = floor(n/2)+1:n;
pp = [pp(n2,:);pp(n1,:)];

% Inverse fourier transform
p = abs(ifft(pp));

