|
View:
New views
2 Messages
—
Rating Filter:
Alert me
|
|
|
implementation of the 2D-radon transformHi all,
I have implemented the 2D-radon transform. It needs a small patch of accumarray: http://www.nabble.com/Small-bug-in-accumarray-tf4873998.html I have checked its output with the radon transform from matlab 2006a. Any comments? Cheers, Alex [radon.m] ## 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/>. ## -*- texinfo -*- ## @deftypefn {Function File} {[@var{RT},@var{xp}] =} radon(@var{I}, @var{theta}) ## @deftypefnx {Function File} {[@var{RT},@var{xp}] =} radon(@var{I}) ## ## Calculates the 2D-Radon transform of the matrix @var{I} at angles given in ## @var{theta}. To each element of @var{theta} corresponds a column in @var{RT}. ## The variable @var{xp} represents the x-axis of the rotated coordinate. ## If @var{theta} is not defined, then 0:179 is assumed. ## @end deftypefn function [RT,xp] = radon (I,theta) if (nargin == 0 | nargin > 2) print_usage (); elseif (nargin == 1) theta = 0:179; endif 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) # 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); endfor endfunction %!test %! A = radon(ones(2,2),30); %! assert (A,[0 0 0.608253175473055 2.103325780167649 1.236538105676658 0.051882938682637 0]',1e-10) |
|
|
Re: implementation of the 2D-radon transformAm Montag, den 03.12.2007, 09:33 +0100 schrieb Alexander Barth: > Hi all, > I have implemented the 2D-radon transform. It needs a small patch of > accumarray: > http://www.nabble.com/Small-bug-in-accumarray-tf4873998.html > > I have checked its output with the radon transform from matlab 2006a. > Any comments? I suggest the attached changes. One call less to size and it seems "I" must be a matrix. Thomas [radon.diff] diff -r cb3577a42a7c radon.m --- a/radon.m Mon Dec 03 12:12:09 2007 +0100 +++ b/radon.m Mon Dec 03 12:35:34 2007 +0100 @@ -28,14 +28,13 @@ function [RT,xp] = radon (I,theta) - if (nargin == 0 | nargin > 2) + if (nargin == 0 | nargin > 2 | !ismatrix(I)) print_usage (); elseif (nargin == 1) theta = 0:179; endif - m = size (I,1); - n = size (I,2); + [m,n] = size (I); # center of image |
| Free embeddable forum powered by Nabble | Forum Help |