A small note on Matlab iradon and the all-at-once vs. the one-at-a ...
A small note on Matlab iradon and the all-at-once vs. the one-at-a ...
A small note on Matlab iradon and the all-at-once vs. the one-at-a ...
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
A <str<strong>on</strong>g>sm<strong>all</strong></str<strong>on</strong>g> <str<strong>on</strong>g>note</str<strong>on</strong>g> <strong>on</strong> <strong>M<strong>at</strong>lab</strong> irad<strong>on</strong> <strong>and</strong> <strong>the</strong> <strong>all</strong>-<strong>at</strong>-<strong>on</strong>ce <strong>vs</strong>.<br />
<strong>the</strong> <strong>on</strong>e-<strong>at</strong>-a-time method<br />
C<strong>on</strong>tents<br />
Nasser M. Abbasi.<br />
June 2, 2012<br />
1 Introducti<strong>on</strong> 1<br />
2 Rad<strong>on</strong> transform introducti<strong>on</strong> 2<br />
3 <strong>M<strong>at</strong>lab</strong> irad<strong>on</strong> <strong>and</strong> <strong>the</strong> <strong>all</strong>-<strong>at</strong>-<strong>on</strong>ce <strong>vs</strong> <strong>the</strong> <strong>on</strong>e-<strong>at</strong>-time 10<br />
4 References 12<br />
1 Introducti<strong>on</strong><br />
This <str<strong>on</strong>g>sm<strong>all</strong></str<strong>on</strong>g> <str<strong>on</strong>g>note</str<strong>on</strong>g> was motiv<strong>at</strong>ed by a strange result I found when using <strong>M<strong>at</strong>lab</strong> irad<strong>on</strong>.<br />
In m<strong>at</strong>lab, when using irad<strong>on</strong> to obtain a backprojecti<strong>on</strong> image from a set of projecti<strong>on</strong>s, a<br />
different result is obtained depending if <strong>on</strong>e c<strong>all</strong>s irad<strong>on</strong>() passing it <strong>the</strong> set of projecti<strong>on</strong>s<br />
<strong>all</strong> <strong>at</strong> <strong>on</strong>ce <strong>vs</strong>. if <strong>on</strong>e c<strong>all</strong>s irad<strong>on</strong>() <strong>on</strong>ce for each projecti<strong>on</strong>, <strong>and</strong> <strong>the</strong>n sums <strong>the</strong> resulting set<br />
of backprojecti<strong>on</strong>s.<br />
The first above method, we will c<strong>all</strong> <strong>the</strong> <strong>all</strong>-<strong>at</strong>-<strong>on</strong>ce method. The sec<strong>on</strong>d is <strong>the</strong> <strong>on</strong>e-<strong>at</strong>-time<br />
method.<br />
The difference between <strong>the</strong> above 2 methods, is th<strong>at</strong> <strong>the</strong> <strong>on</strong>e-<strong>at</strong>-time method results in an<br />
image whose intensity levels is 2N times th<strong>at</strong> of <strong>the</strong> image resulting from <strong>the</strong> <strong>all</strong>-<strong>at</strong>-<strong>on</strong>ce<br />
method. Where N is <strong>the</strong> number of projecti<strong>on</strong>s.<br />
I set about to determine why this is <strong>the</strong> case. And this <str<strong>on</strong>g>note</str<strong>on</strong>g> is <strong>the</strong> result of this investig<strong>at</strong>i<strong>on</strong><br />
showing <strong>the</strong> reas<strong>on</strong> for this difference.<br />
1
2 Rad<strong>on</strong> transform introducti<strong>on</strong><br />
The equ<strong>at</strong>i<strong>on</strong> of <strong>the</strong> line L can be written in 2 ways. The st<strong>and</strong>ard way is<br />
y = mx + b<br />
where m is <strong>the</strong> slope <strong>and</strong> b is <strong>the</strong> intercept. It also can be written in terms of <strong>the</strong> parameters<br />
p <strong>and</strong> θ as<br />
L (p, θ) = {(x, y) : x cos θ + y sin θ = p}<br />
Any point (x, y) <strong>on</strong> <strong>the</strong> line L with specific p <strong>and</strong> specific θ s<strong>at</strong>isfy x cos θ + y sin θ = p<br />
Assume now <strong>the</strong>re exist a functi<strong>on</strong> f (x, y) defined over <strong>the</strong> regi<strong>on</strong> shown above. The integral<br />
of this functi<strong>on</strong> over <strong>the</strong> line L (p, θ) is<br />
<br />
f (x, y) ds<br />
where ds is a differential element of <strong>the</strong> line<br />
L<br />
2
It would be more simpler to express <strong>the</strong> above integral in terms of x <strong>and</strong> y. To do th<strong>at</strong>, a<br />
trick is used with <strong>the</strong> help of <strong>the</strong> delta functi<strong>on</strong>. The above integral can be written as<br />
∞<br />
∞<br />
y=−∞x=−∞<br />
f (x, y) δ (x cos θ + y sin θ − p) dxdy<br />
Hence for a specific p, θ <strong>the</strong> above will integr<strong>at</strong>e f (x, y) over <strong>the</strong> line L (p, θ). The above is<br />
<strong>the</strong> rad<strong>on</strong> transform of f (x, y) over <strong>the</strong> line L (p, θ). So <strong>the</strong> rad<strong>on</strong> transform is re<strong>all</strong>y <strong>the</strong><br />
line integral of a f (x, y)<br />
The result of <strong>the</strong> above rad<strong>on</strong> transform is <strong>on</strong>e numerical value. It is <strong>the</strong> line integral value.<br />
We can imagine a projecti<strong>on</strong> line into which we accumul<strong>at</strong>e <strong>the</strong> result of <strong>the</strong>se line integrals<br />
as follows<br />
Now suppose we have many par<strong>all</strong>el lines to L <strong>and</strong> we perform <strong>the</strong> line integral of f (x, y)<br />
over each of <strong>the</strong>se lines (since <strong>all</strong> <strong>the</strong>se lines are par<strong>all</strong>el to line L, <strong>the</strong>n <strong>all</strong> of <strong>the</strong>m will<br />
have <strong>the</strong> same θ, but <strong>the</strong>y will have different p each). This will result in many line of <strong>the</strong><br />
projecti<strong>on</strong> line as follows<br />
3
So, if we do <strong>the</strong> above over many par<strong>all</strong>el lines, we obtain many sample points <strong>on</strong> <strong>the</strong><br />
projecti<strong>on</strong> line z, Notice th<strong>at</strong> <strong>the</strong> projecti<strong>on</strong> line z in <strong>the</strong> above diagram is some arbitrary<br />
line drawn just to collect <strong>the</strong> result of <strong>the</strong> line integrals into. It represents a detector which<br />
collects <strong>the</strong> results of each line integral. If we collect many line integrals to cover <strong>the</strong> whole<br />
regi<strong>on</strong>. Hence for each specific angle θi we obtain a projecti<strong>on</strong> vector gi as shown in <strong>the</strong><br />
following diagram<br />
The projecti<strong>on</strong> shown above is a discrete functi<strong>on</strong>. It is a functi<strong>on</strong> of p <strong>and</strong> θ. Hence we<br />
have g (p, θ). But for <strong>the</strong> same angle θ, g is a functi<strong>on</strong> of p, So some books write gθ (p).<br />
Notice th<strong>at</strong> z is par<strong>all</strong>el to p, <strong>and</strong> can be c<strong>all</strong>ed <strong>the</strong> axis of <strong>the</strong> projecti<strong>on</strong>.<br />
Once <strong>the</strong> projecti<strong>on</strong> gθ (p) is obtained, <strong>the</strong>n it is c<strong>on</strong>verted to <strong>the</strong> (discrete) Fourier domain<br />
using FFT. The discrete Fourier transform is<br />
N−1 <br />
<br />
Gk = gn exp − 2πi<br />
N kn<br />
<br />
n=0<br />
k = 0, 1, · · · , N − 1<br />
Hence we obtain <strong>the</strong> vector G which is <strong>the</strong> discrete Fourier transform of <strong>the</strong> projecti<strong>on</strong><br />
g, This is illustr<strong>at</strong>ed in <strong>the</strong> following diagram. Notice th<strong>at</strong> <strong>the</strong> numbers Gk are complex<br />
numbers <strong>and</strong> hence have phase <strong>and</strong> magnitude. In <strong>the</strong> implement<strong>at</strong>i<strong>on</strong> of <strong>the</strong> discrete fourier<br />
transform, <strong>the</strong> FFT is used for performance.<br />
4
So, why do we do <strong>the</strong> above? The reas<strong>on</strong> is to filter <strong>the</strong> projecti<strong>on</strong> d<strong>at</strong>a. Filtering <strong>the</strong><br />
projecti<strong>on</strong> produces better backprojecti<strong>on</strong> (sharper) than without filtering (more blurred). It<br />
is easier to apply filtering in <strong>the</strong> frequency domain than in <strong>the</strong> sp<strong>at</strong>ial domain (multiplic<strong>at</strong>i<strong>on</strong><br />
<strong>vs</strong> c<strong>on</strong>voluti<strong>on</strong>). Now th<strong>at</strong> <strong>the</strong> FFT is d<strong>on</strong>e <strong>and</strong> G obtained, a filter is selected. C<strong>on</strong>sider<br />
<strong>the</strong> ram-lak filter. This filter has a frequency resp<strong>on</strong>se as follows 1<br />
So, assume <strong>the</strong> filter frequency spectrum is given by <strong>the</strong> vector H, (this is a complex vector,<br />
since it is <strong>the</strong> frequency spectrum of <strong>the</strong> filter). Hence <strong>the</strong> filtered backprojecti<strong>on</strong> is given<br />
by<br />
˜G = GH<br />
Where I use <strong>the</strong> tilde symbol to represent a filtered frequency resp<strong>on</strong>se.<br />
Now th<strong>at</strong> we filtered <strong>the</strong> projecti<strong>on</strong>, we need to return back to <strong>the</strong> sp<strong>at</strong>ial domain. Hence<br />
we obtain ˜g by inverse discrete fourier transform of ˜G <strong>and</strong> this is given by<br />
˜gn = 1<br />
N−1 <br />
<br />
2πi<br />
˜Gk exp<br />
N<br />
N<br />
k=0<br />
kn<br />
<br />
n = 0, 1, · · · , N − 1<br />
Now we have obtain <strong>the</strong> sp<strong>at</strong>ial represent<strong>at</strong>i<strong>on</strong> ˜g of <strong>the</strong> projecti<strong>on</strong> g after being filtered.<br />
However, this c<strong>on</strong>tains both complex <strong>and</strong> real comp<strong>on</strong>ents (since it is complex valued as<br />
1 reference: http://dukemil.egr.duke.edu/XRAY/CT/Simul<strong>at</strong>i<strong>on</strong>/ct in.html<br />
5
esult of <strong>the</strong> IFFT). Then we need to take its real part<br />
˜g = real (˜g)<br />
The above is illustr<strong>at</strong>ed by <strong>the</strong> following diagram<br />
The above can also be represented using plots of <strong>the</strong> sp<strong>at</strong>ial <strong>and</strong> frequency spectrum of <strong>the</strong><br />
above vectors. For <strong>the</strong>se plots, I used a projecti<strong>on</strong> signal made up from some simple functi<strong>on</strong><br />
of x. The plots shown are <strong>the</strong> actual FFT <strong>and</strong> IFFT <strong>and</strong> <strong>the</strong> filter ram-lak used to obtain<br />
<strong>the</strong> filtered backprojecti<strong>on</strong><br />
6
Now th<strong>at</strong> <strong>the</strong> filtered projecti<strong>on</strong> is obtained, <strong>the</strong>n backprojecti<strong>on</strong> is d<strong>on</strong>e. Notice th<strong>at</strong> <strong>the</strong><br />
filtering, when we talk about filtered backprojecti<strong>on</strong>, is carried <strong>on</strong> <strong>the</strong> projecti<strong>on</strong> itself, <strong>and</strong><br />
not <strong>on</strong> <strong>the</strong> backprojecti<strong>on</strong>. I am not sure if it is possible to do backprojecti<strong>on</strong> <strong>on</strong> <strong>the</strong><br />
projecti<strong>on</strong> first, <strong>the</strong>n apply filtering <strong>on</strong> <strong>the</strong> resulting backprojecti<strong>on</strong> image.<br />
The filtered projecti<strong>on</strong> is ˜gθ (p), where <strong>the</strong> tilde indic<strong>at</strong>es this is a filtered projecti<strong>on</strong>. Now<br />
th<strong>at</strong> we have calcul<strong>at</strong>ed ˜gθ (p), we can obtain <strong>the</strong> backprojecti<strong>on</strong>, which will be a 2D functi<strong>on</strong>.<br />
Assume <strong>the</strong> original functi<strong>on</strong> (which we do not know in practice, was f (x, y), <strong>the</strong>n let <strong>the</strong><br />
backprojecti<strong>on</strong> functi<strong>on</strong> be fB (x, y). Hence<br />
fB (x, y) =<br />
π<br />
θ=0<br />
7<br />
˜gθ (p) dθ
But p = x cos θ + y sin θ, hence <strong>the</strong> above becomes<br />
fB (x, y) =<br />
π<br />
θ=0<br />
˜gθ (x cos θ + y sin θ) dθ<br />
Wh<strong>at</strong> <strong>the</strong> above is saying, is th<strong>at</strong> to find fB (x, y) <strong>at</strong> some x, y positi<strong>on</strong>, <strong>the</strong> angle θ is changed<br />
to cover <strong>all</strong> <strong>the</strong> angles from zero to 1800 , <strong>and</strong> for each angle in this interval, <strong>the</strong> functi<strong>on</strong><br />
˜gθ (p) is evalu<strong>at</strong>ed <strong>at</strong> p = x cos θ + y sin θ. The sum of <strong>all</strong> <strong>the</strong>se gives fB <strong>at</strong> th<strong>at</strong> x, y values.<br />
We do <strong>the</strong>se for each x, y value in <strong>the</strong> regi<strong>on</strong> to obtain <strong>all</strong> <strong>the</strong> values of fB. Assume <strong>the</strong>re<br />
are N projecti<strong>on</strong>s made. Hence N angles (since each projecti<strong>on</strong> corresp<strong>on</strong>ds to <strong>on</strong>e angle).<br />
Then <strong>the</strong> discrete versi<strong>on</strong> of <strong>the</strong> above integral becomes<br />
<br />
N−1 <br />
fB (x, y) = ˜gθm (x cos θm + y sin θm) ∆θ<br />
m=0<br />
Since <strong>the</strong>re are N angles, <strong>the</strong>n we divide π by N to obtain each specific angle in <strong>the</strong> range.<br />
Hence<br />
θm = π<br />
N m<br />
And also we see th<strong>at</strong> ∆θ = π<br />
N<br />
fB (x, y) = π<br />
So <strong>the</strong> sum becomes<br />
N−1 <br />
N<br />
m=0<br />
˜gθm<br />
x cos π<br />
N m + y sin π<br />
N m<br />
And <strong>the</strong> above is <strong>the</strong> equ<strong>at</strong>i<strong>on</strong> used for <strong>the</strong> backprojecti<strong>on</strong>. The following diagram illustr<strong>at</strong>es<br />
<strong>the</strong> above.<br />
Notice th<strong>at</strong> in <strong>the</strong> above, backprojecti<strong>on</strong> is carried out in <strong>the</strong> sp<strong>at</strong>ial domain. This is how <strong>the</strong><br />
<strong>M<strong>at</strong>lab</strong> irad<strong>on</strong> does it. O<strong>the</strong>r way to do backprojecti<strong>on</strong> is to stay in <strong>the</strong> frequency domain<br />
by using <strong>the</strong> central slice <strong>the</strong>orem. This is d<strong>on</strong>e as follows: One <strong>the</strong> fourier transform of <strong>the</strong><br />
8<br />
(1)
projecti<strong>on</strong> is found, it is moved to <strong>the</strong> 2D plane which represents <strong>the</strong> 2D fourier transform<br />
of <strong>the</strong> image being rec<strong>on</strong>structed by <strong>the</strong> backprojecti<strong>on</strong>. It goes into a radial line through<br />
<strong>the</strong> center of <strong>the</strong> 2D fourier transform <strong>at</strong> <strong>the</strong> same angle θ of <strong>the</strong> projecti<strong>on</strong>. This is d<strong>on</strong>e<br />
for each projecti<strong>on</strong>. The result is a 2D fourier transform of <strong>the</strong> image. However, it is filled<br />
radi<strong>all</strong>y. This diagram from Kak illustr<strong>at</strong>es this:<br />
Then filtering is d<strong>on</strong>e now in <strong>the</strong> frequency domain. Next, gridding is carried out to transform<br />
<strong>the</strong> above to a Cartesian coordin<strong>at</strong>es since IFFT works <strong>on</strong> <strong>the</strong>se <strong>on</strong>ly (by interpol<strong>at</strong>i<strong>on</strong>). Then<br />
IFFT is d<strong>on</strong>e to obtain <strong>the</strong> final backprojecti<strong>on</strong> image.<br />
But since <strong>the</strong> purpose of this <str<strong>on</strong>g>note</str<strong>on</strong>g> is to talk about <strong>M<strong>at</strong>lab</strong> irad<strong>on</strong>(), <strong>the</strong>n we will use (1) as<br />
<strong>the</strong> method of backprojecti<strong>on</strong>.<br />
9
3 <strong>M<strong>at</strong>lab</strong> irad<strong>on</strong> <strong>and</strong> <strong>the</strong> <strong>all</strong>-<strong>at</strong>-<strong>on</strong>ce <strong>vs</strong> <strong>the</strong> <strong>on</strong>e-<strong>at</strong>-time<br />
Now we start <strong>the</strong> investig<strong>at</strong>i<strong>on</strong> <strong>on</strong> why when using <strong>M<strong>at</strong>lab</strong> to determine backprojecti<strong>on</strong> from<br />
a set of projecti<strong>on</strong>s it gives different results depending if <strong>the</strong> c<strong>all</strong> is made in <strong>all</strong>-<strong>at</strong>-<strong>on</strong>ce <strong>vs</strong>.<br />
<strong>on</strong>e-<strong>at</strong>-a-time.<br />
Let c<strong>on</strong>sider <strong>the</strong> <strong>all</strong>-<strong>at</strong>-<strong>on</strong>ce first. From (1) we see th<strong>at</strong> <strong>the</strong> backprojecti<strong>on</strong> image is<br />
fB (x, y) = π<br />
N−1 <br />
˜gθm<br />
N<br />
m=0<br />
If we c<strong>all</strong> <strong>the</strong> sum as img, <strong>the</strong>n <strong>the</strong> above becomes<br />
fB (x, y) = π<br />
N img<br />
<br />
π<br />
x cos<br />
N m<br />
<br />
π<br />
+ y sin<br />
N m<br />
<br />
Notice however, th<strong>at</strong> m<strong>at</strong>lab irad<strong>on</strong>.m does <strong>the</strong> following <strong>at</strong> <strong>the</strong> end: (type irad<strong>on</strong>.m to see)<br />
fB = π<br />
img (2)<br />
2N<br />
I am not sure now why <strong>M<strong>at</strong>lab</strong> divides by an extra 2. I think this might be because if <strong>the</strong><br />
angles given <strong>at</strong> from 0 to 3600 , <strong>the</strong>n <strong>the</strong>re is a double counting involved (since <strong>the</strong> image can<br />
be fully c<strong>on</strong>structed from 0 to 1800 , <strong>and</strong> hence it assumes <strong>the</strong> angles given have full range<br />
of 2π, <strong>and</strong> so to compens<strong>at</strong>e for doubling <strong>the</strong> intensity of <strong>the</strong> image, it divides by an extra<br />
2 <strong>at</strong> <strong>the</strong> end.<br />
So, now th<strong>at</strong> (2) gives <strong>the</strong> backprojecti<strong>on</strong> in <strong>the</strong> <strong>all</strong>-<strong>at</strong>-<strong>on</strong>ce method, let c<strong>on</strong>sider <strong>the</strong> <strong>on</strong>e-<strong>at</strong>time<br />
method. Supposed again we have N angles, <strong>and</strong> we c<strong>all</strong> irad<strong>on</strong> N times. But each time<br />
we c<strong>all</strong> irad<strong>on</strong> with <strong>on</strong>e angle, we have to pass <strong>the</strong> same angle twice, <strong>and</strong> <strong>the</strong> same projecti<strong>on</strong><br />
twice, <strong>and</strong> divide <strong>the</strong> result by 2. From help:<br />
Compute <strong>the</strong> backprojecti<strong>on</strong> of a single projecti<strong>on</strong> vector. The IRADON<br />
syntax does not <strong>all</strong>ow you to do this directly, because if THETA is a<br />
scalar it is tre<strong>at</strong>ed as an increment. You can accomplish <strong>the</strong> task by<br />
passing in two copies of <strong>the</strong> projecti<strong>on</strong> vector <strong>and</strong> <strong>the</strong>n dividing <strong>the</strong><br />
result by 2.<br />
So, in each c<strong>all</strong> now, N = 2, <strong>and</strong> so we write<br />
<br />
π<br />
fB1 =<br />
2 × 2 img1<br />
<br />
/2 = π<br />
8 img1<br />
<br />
π<br />
fB2 =<br />
2 × 2 img2<br />
<br />
/2 = π<br />
8 img2<br />
.<br />
fBN =<br />
<br />
π<br />
2 × 2 imgN<br />
<br />
/2 = π<br />
8 imgN<br />
10
Now we add <strong>all</strong> <strong>the</strong> above <strong>and</strong> obtain<br />
fB1 + fB2 + · · · + fBN<br />
= π<br />
8 (img1 + img2 + · · · + imgN) (3)<br />
Now, img1 + img2 + · · · + imgN must be twice <strong>the</strong> img from <strong>the</strong> c<strong>all</strong> to irad<strong>on</strong> in <strong>the</strong> <strong>on</strong>ce-<strong>at</strong>time<br />
method, since using <strong>the</strong> same assumpti<strong>on</strong> as <strong>M<strong>at</strong>lab</strong>, where it assumed 0 to 360 0 range<br />
<strong>and</strong> not 0 to 180 0 , we will double add <strong>the</strong> intensity. Hence (3) becomes<br />
fB1 + fB2 + · · · + fBN<br />
π<br />
=<br />
8 (2img)<br />
= π<br />
img (4)<br />
4<br />
Compare (4), which is <strong>the</strong> <strong>on</strong>e-<strong>at</strong>-time, with (2), which is <strong>the</strong> <strong>all</strong>-<strong>at</strong>-<strong>on</strong>ce, we see th<strong>at</strong><br />
Therefore, we see th<strong>at</strong><br />
Hence <strong>the</strong> <strong>on</strong>e-<strong>at</strong>-time result is N<br />
2<br />
π<br />
fB1 + fB2 + · · · + fBN =<br />
4 img<br />
fB = π<br />
2N img<br />
fB1 + fB2 + · · · + fBN<br />
fB<br />
=<br />
= N<br />
2<br />
π<br />
4 img<br />
π<br />
2N img<br />
times <strong>the</strong> <strong>all</strong>-<strong>at</strong>-<strong>on</strong>ce. And this is wh<strong>at</strong> was found.<br />
Therefore, when using irad<strong>on</strong>() to obtain a backprojecti<strong>on</strong> in <strong>the</strong> <strong>on</strong>e-<strong>at</strong>-time method, we<br />
times <strong>the</strong> image th<strong>at</strong> would have been obtained if using <strong>the</strong> <strong>all</strong>-<strong>at</strong>-<strong>on</strong>ce method. .<br />
obtain N<br />
2<br />
11
4 References<br />
1. http://www.comap.com/product/samples/UMM794.pdf<br />
2. Principles of computerized tomographic imaging by Kak <strong>and</strong> Slaney<br />
3. <strong>M<strong>at</strong>lab</strong> rad<strong>on</strong> <strong>and</strong> irad<strong>on</strong> help.<br />
12