function [RT,xp] = radon(I,theta)

% Copyright (C) 2007 Alexander Barth <barth.alexander@...>
%
% This program is free software; you can redistribute it and/or modify it
% under the terms of the GNU General Public License as published by
% the Free Software Foundation; either version 3 of the License, or (at
% your option) any later version.
%
% This program is distributed in the hope that it will be useful, but
% WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
% General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with this program; see the file COPYING.  If not, see
% http://www.gnu.org/licenses
%
% Taken from the OCTAVE project
% Course in Wavelets, TU Chemnitz, 2010

  m = size (I,1);
  n = size (I,2);

  % center of image

  xc = floor ((m+1)/2);
  yc = floor ((n+1)/2);

  % divide each pixel into 2x2 subpixels

  d = reshape (I,[1 m 1 n]);
  d = d([1 1],:,[1 1],:);
  d = reshape (d,[2*m 2*n])/4;

  b = ceil (sqrt (sum (size (I).^2))/2 + 1);
  xp = [-b:b]';
  sz = size(xp);

  [X,Y] = ndgrid (0.75 - xc + [0:2*m-1]/2,0.75 - yc + [0:2*n-1]/2);

  X = X(:)';
  Y = Y(:)';
  d = d(:)';

  th = theta*pi/180;

  for l=1:length (theta)
l
    % project each pixel to vector (-sin(th),cos(th))
    Xp = -sin (th(l)) * X + cos (th(l)) * Y;
   
    ip = Xp + b + 1;

    k = floor (ip);
    frac = ip-k;

    RT(:,l) = accumarray (k',d .* (1-frac),sz) + accumarray (k'+1,d .* frac,sz);
  end

end
