1 ## Copyright (C) 2007 Alexander Barth <barth.alexander@gmail.com>
4 ## This program is free software; you can redistribute it and/or modify it
5 ## under the terms of the GNU General Public License as published by
6 ## the Free Software Foundation; either version 3 of the License, or (at
7 ## your option) any later version.
9 ## This program is distributed in the hope that it will be useful, but
10 ## WITHOUT ANY WARRANTY; without even the implied warranty of
11 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 ## General Public License for more details.
14 ## You should have received a copy of the GNU General Public License
15 ## along with this program; see the file COPYING. If not, see
16 ## <http://www.gnu.org/licenses/>.
19 ## @deftypefn {Function File} {[@var{RT},@var{xp}] =} radon(@var{I}, @var{theta})
20 ## @deftypefnx {Function File} {[@var{RT},@var{xp}] =} radon(@var{I})
22 ## Calculates the 2D-Radon transform of the matrix @var{I} at angles given in
23 ## @var{theta}. To each element of @var{theta} corresponds a column in @var{RT}.
24 ## The variable @var{xp} represents the x-axis of the rotated coordinate.
25 ## If @var{theta} is not defined, then 0:179 is assumed.
29 function [RT,xp] = radon (I,theta)
32 if (nargin == 0 || nargin > 2)
38 if (!ismatrix(I) || ndims(I) != 2)
39 error("radon: first input must be a MxN matrix");
43 error("radon: second input must be a vector");
52 # divide each pixel into 2x2 subpixels
54 d = reshape (I,[1 m 1 n]);
55 d = d([1 1],:,[1 1],:);
56 d = reshape (d,[2*m 2*n])/4;
58 b = ceil (sqrt (sum (size (I).^2))/2 + 1);
62 [X,Y] = ndgrid (0.75 - xc + [0:2*m-1]/2,0.75 - yc + [0:2*n-1]/2);
70 for l=1:length (theta)
71 # project each pixel to vector (-sin(th),cos(th))
72 Xp = -sin (th(l)) * X + cos (th(l)) * Y;
79 RT(:,l) = accumarray (k',d .* (1-frac),sz) + accumarray (k'+1,d .* frac,sz);
85 %! A = radon(ones(2,2),30);
86 %! assert (A,[0 0 0.608253175473055 2.103325780167649 1.236538105676658 0.051882938682637 0]',1e-10)