Algorithm Search⌘K

Algorithmcore

Fan-beam filtered back-projection

Also called fan-beam FBP.

Reconstruct a CT slice from rays that diverge from a point source. Weight each projection, filter it with a modified ramp, and back-project with the inverse squared source distance.

Time
O(a d log d + a n^2) worst
Space
O(a d + n^2) extra
Where
a = the number of source positions; d = the number of detector bins; n = the side of the n x n output image
Properties
deterministicnot in placenot iterativelineariterative
Origin
G. T. Herman, A. V. Lakshminarayanan, A. Naparstek, 1976

Fan-beam filtered back-projection reconstructs a 2D image from the data of a CT scanner whose rays leave a point source and spread out in a fan. It is a version of filtered back-projection that works on the fan data directly. Each projection is multiplied by a cosine weight and convolved with a modified ramp kernel, and each filtered projection is smeared back along its diverging rays with the weight 1/L21/L^2, where LL is the distance from the source. With aa source positions, dd detector bins and an n×nn \times n image it takes O(adlog⁡d+an2)O(a d \log d + a n^2) time with an FFT. A full scan of 2π2\pi gives each line twice. A short scan of π\pi plus the fan angle is enough with Parker's weights.

In plain words

In a fan-beam scanner a small X-ray source and a curved detector turn around the patient together. The rays from the source fan out over the patient, so one projection does not hold parallel rays.

The method makes three changes to parallel FBP. First, each reading gets a cosine weight, because the fan spaces the rays unevenly. Second, the filter shape is stretched in the same way that the fan stretches the spacing of the rays. Third, when a filtered projection is smeared back, each point gets the value of the ray from the source through it, divided by the square of its distance to the source. Points near the source see the fan through a wide angle, and the division corrects for that. Then the sum over all source positions gives the image, as in the parallel case.

The problem

The source at the angle β\beta is at S(β)=D ω⊥(β)S(\beta) = D\,\omega^\perp(\beta), at the distance DD from the center of rotation, with ω(β)=(cos⁡β,sin⁡β)\omega(\beta) = (\cos\beta, \sin\beta) and ω⊥(β)=(−sin⁡β,cos⁡β)\omega^\perp(\beta) = (-\sin\beta, \cos\beta). The ray with the fan angle γ\gamma leaves S(β)S(\beta) in the direction −ω⊥(β+γ)-\omega^\perp(\beta + \gamma). It is the line {x:x⋅ω(θ)=s}\{x : x\cdot\omega(\theta) = s\} with θ=β+γ\theta = \beta + \gamma and s=Dsin⁡γs = D\sin\gamma. So the fan data is

g(β,γ)=Rf(β+γ,Dsin⁡γ),g(\beta, \gamma) = \mathcal{R}f(\beta + \gamma, D\sin\gamma),

where Rf(θ,s)=∫f(s ω+t ω⊥) dt\mathcal{R}f(\theta, s) = \int f(s\,\omega + t\,\omega^\perp)\,dt is the Radon transform. Each value is a line integral of the attenuation, which the scanner gets from the intensities by the Beer-Lambert law. The unknown ff is zero outside a disk of radius r<Dr < D.

An equiangular detector samples γj=(j−(d−1)/2)α\gamma_j = (j - (d-1)/2)\alpha for j=0,…,d−1j = 0, \ldots, d - 1. A flat detector samples tj=(j−(d−1)/2)τt_j = (j - (d-1)/2)\tau on a line through the center normal to the central ray, and its ray has the fan angle arctan⁡(tj/D)\arctan(t_j/D). A full scan takes βk=2πk/a\beta_k = 2\pi k/a for k=0,…,a−1k = 0, \ldots, a - 1. The output is an n×nn \times n image on [−1,1]2[-1, 1]^2. Pixel (i,j)(i, j) has its center at xj=−1+(2j+1)/nx_j = -1 + (2j+1)/n and yi=1−(2i+1)/ny_i = 1 - (2i+1)/n, so row 0 is at the top and yy goes up.

For a point xx and a source S(β)S(\beta), let LL be the distance from the source to xx and γ′\gamma' the fan angle of the ray through xx:

Lcos⁡γ′=D−x⋅ω⊥(β),Lsin⁡γ′=x⋅ω(β).L\cos\gamma' = D - x\cdot\omega^\perp(\beta), \qquad L\sin\gamma' = x\cdot\omega(\beta).

The algorithm evaluates the fan-beam inversion formula

f(x)=∫02π1L2∫κ(γ′−γ) Dcos⁡γ g(β,γ) dγ dβ,κ(u)=12(usin⁡u)2h(u),f(x) = \int_0^{2\pi} \frac{1}{L^2}\int \kappa(\gamma' - \gamma)\,D\cos\gamma\,g(\beta, \gamma)\,d\gamma\,d\beta, \qquad \kappa(u) = \frac{1}{2}\left(\frac{u}{\sin u}\right)^2 h(u),

where hh is the ramp filter, the filter with the frequency response ∣σ∣|\sigma| in ordinary frequency. The proof below derives it from the parallel formula.

The algorithm

  1. FAN-FBP(g, D, α, n) ▷ g[k][j]: source angle β_k = 2πk/a, fan angle γ_j = (j - (d-1)/2) α
  2. 1a, d ← the number of rows and of columns of g
  3. 2κ[m] ← 1/(8α²) for m = 0, 0 for even m, -1/(2π² sin²(mα)) for odd m, m = -(d-1) .. d-1
  4. 3for k ← 0 to a - 1 do
  5. 4p[j] ← D cos(γ_j) · g[k][j] for each j
  6. 5q_k[j] ← α Σ_l κ[j - l] p[l] for each j ▷ direct sum, or an FFT with zero padding to 2d - 1
  7. 6for each pixel (i, j) with center x = (x_j, y_i) do
  8. 7for each k: (L cos γ', L sin γ') ← (D - x·ω⊥(β_k), x·ω(β_k))
  9. 8f[i][j] ← Σ_k LININTERP(q_k, γ'/α + (d-1)/2) / L²
  10. 9return (2π/a) · f

Line L2 is the sampled kernel κ(mα)=12(mα/sin⁡mα)2hB(mα)\kappa(m\alpha) = \frac{1}{2}(m\alpha/\sin m\alpha)^2 h_B(m\alpha), where hBh_B is the Ram-Lak kernel: the ramp cut off at the Nyquist frequency 1/(2α)1/(2\alpha) of the angular sampling. Since hB(mα)=−1/(m2π2α2)h_B(m\alpha) = -1/(m^2\pi^2\alpha^2) for odd mm, the factor (mα)2(m\alpha)^2 cancels and only sin⁡2(mα)\sin^2(m\alpha) remains. Line L4 is the cosine weight. Line L5 is an aperiodic discrete convolution. Line L8 reads the filtered projection at the fan angle γ′\gamma' of the ray through the pixel, by linear interpolation with 0 outside the detector, and divides by L2L^2. Line L9 multiplies by the angle step.

For a flat detector, line L4 uses the weight D/D2+tj2D/\sqrt{D^2 + t_j^2}, line L2 uses hB/2h_B/2 with the spacing τ\tau, and line L8 reads the filtered projection at t′=D x⋅ω/(D−x⋅ω⊥)t' = D\,x\cdot\omega/(D - x\cdot\omega^\perp) and divides by U2U^2 with U=(D−x⋅ω⊥)/DU = (D - x\cdot\omega^\perp)/D. The code has both versions.

Short scan. Each line is measured twice in a full scan: the ray (β,γ)(\beta, \gamma) and the ray (β+π+2γ,−γ)(\beta + \pi + 2\gamma, -\gamma) are the same line. A scan over β∈[0,π+2δ]\beta \in [0, \pi + 2\delta], with δ\delta at least the half fan angle, measures every line at least once. Parker's weights are

w(β,γ)={sin⁡2 ⁣(π4βδ−γ)0≤β<2(δ−γ),12(δ−γ)≤β≤π−2γ,sin⁡2 ⁣(π4π+2δ−βδ+γ)π−2γ<β≤π+2δ,w(\beta, \gamma) = \begin{cases} \sin^2\!\left(\frac{\pi}{4}\frac{\beta}{\delta - \gamma}\right) & 0 \le \beta < 2(\delta - \gamma), \\ 1 & 2(\delta - \gamma) \le \beta \le \pi - 2\gamma, \\ \sin^2\!\left(\frac{\pi}{4}\frac{\pi + 2\delta - \beta}{\delta + \gamma}\right) & \pi - 2\gamma < \beta \le \pi + 2\delta, \end{cases}

and the weights of the two copies of each line add to 1. The short scan multiplies line L4 by w(βk,γj)w(\beta_k, \gamma_j), takes βk=k(π+2δ)/a\beta_k = k(\pi + 2\delta)/a, and uses the factor 2(π+2δ)/a2(\pi + 2\delta)/a in line L9. The formulas here are written in the geometry of this page. Parker's paper uses its own angle conventions.

Example

Take the disk of radius 1/21/2 with density 1 and a source at D=2D = 2. Use d=5d = 5 bins with α=0.15\alpha = 0.15 and a=4a = 4 source positions. The ray with fan angle γ\gamma is at the distance s=2sin⁡γs = 2\sin\gamma from the center, and its line integral is 21/4−s22\sqrt{1/4 - s^2}. The disk is the same at each angle, so all four rows of gg are equal.

quantity values at j=0,…,4j = 0, \ldots, 4
fan angle γj\gamma_j -0.30, -0.15, 0, 0.15, 0.30
data g[k][j]g[k][j] 0, 0.8017, 1, 0.8017, 0
weighted p[j]=2cos⁡(γj) g[k][j]p[j] = 2\cos(\gamma_j)\,g[k][j] 0, 1.5854, 2, 1.5854, 0
filtered qk[j]q_k[j] -0.6031, 0.6406, 0.5877, 0.6406, -0.6031

The kernel values are κ(0)=1/(8⋅0.152)=5.5556\kappa(0) = 1/(8 \cdot 0.15^2) = 5.5556, κ(±0.15)=−2.2685\kappa(\pm 0.15) = -2.2685, κ(±0.45)=−0.2678\kappa(\pm 0.45) = -0.2678, and 0 at the even offsets. So qk[2]=0.15 (5.5556⋅2−2⋅2.2685⋅1.5854)=0.5877q_k[2] = 0.15\,(5.5556 \cdot 2 - 2 \cdot 2.2685 \cdot 1.5854) = 0.5877. At the center of the disk, L=D=2L = D = 2 and γ′=0\gamma' = 0 for every source, so line L8 gives 4⋅0.5877/4=0.58774 \cdot 0.5877/4 = 0.5877 and line L9 gives (2π/4)⋅0.5877=0.9232(2\pi/4) \cdot 0.5877 = 0.9232. The true value is 1. The error comes from the coarse sampling.

A finer setup gives a smaller error. The table gives the measured error of the code on exact fan data with D=3D = 3, a fan that covers the disk of radius 2\sqrt{2} (half fan angle 28.13°28.13°), d=49d = 49 bins with α=0.02045\alpha = 0.02045, and n=32n = 32. These numbers are measurements of this setup, not bounds.

scan and phantom result
full scan, a=64a = 64, Gaussian e−4π∣x∣2e^{-4\pi\vert x\vert^2}, largest error 0.0179
short scan with Parker's weights, a=40a = 40 over π+2δ\pi + 2\delta, same Gaussian 0.0182
full scan, flat detector, a=64a = 64, same Gaussian 0.0215
full scan, modified Shepp-Logan phantom (first 5 ellipses), pixel (16,16)(16, 16), true 0.2 0.2097
same, pixel (8,16)(8, 16) inside the small top ellipse, true 0.3 0.3087

The short scan uses 40 source positions against 64 for the full scan, and the error is almost the same.

Correctness

The proof in proofs/correctness.md starts from the parallel formula f(x)=12∫02π(h∗Rf(θ,⋅))(x⋅ω) dθf(x) = \frac{1}{2}\int_0^{2\pi} (h * \mathcal{R}f(\theta, \cdot))(x\cdot\omega)\,d\theta, with the ramp written as a finite-part integral. It changes the variables from (θ,s)(\theta, s) to (β,γ)(\beta, \gamma). The Jacobian of (θ,s)=(β+γ,Dsin⁡γ)(\theta, s) = (\beta + \gamma, D\sin\gamma) is Dcos⁡γD\cos\gamma, which gives the weight of line L4. The distance from xx to the ray (β,γ)(\beta, \gamma) is x⋅ω(β+γ)−Dsin⁡γ=Lsin⁡(γ′−γ)x\cdot\omega(\beta + \gamma) - D\sin\gamma = L\sin(\gamma' - \gamma). The ramp kernel is homogeneous of degree −2-2, so h(Lsin⁡u)=L−2(u/sin⁡u)2h(u)h(L\sin u) = L^{-2}(u/\sin u)^2 h(u). This gives both the factor 1/L21/L^2 and the kernel κ\kappa. A lemma on finite parts shows that the change of the cut around the singular point does not change the result, and that the singular terms on both sides cancel. The same argument gives the flat-detector formula. For the short scan, any weight whose values on the two copies of each line add to 1 gives the same image, and Parker's weights have this property. The discrete algorithm then approximates the formula by the band-limited kernel, the sum over the bins, linear interpolation and the sum over the source angles.

Proof: Correctness of fan-beam filtered back-projectionfull

We use the conventions of the page. ω(θ)=(cos⁡θ,sin⁡θ)\omega(\theta) = (\cos\theta, \sin\theta) and ω⊥(θ)=(−sin⁡θ,cos⁡θ)\omega^\perp(\theta) = (-\sin\theta, \cos\theta). The Radon transform is p(θ,s)=Rf(θ,s)=∫f(s ω+t ω⊥) dtp(\theta, s) = \mathcal{R}f(\theta, s) = \int f(s\,\omega + t\,\omega^\perp)\,dt, now for all θ∈R\theta \in \mathbb{R}, so that p(θ+π,−s)=p(θ,s)p(\theta + \pi, -s) = p(\theta, s). The source at the angle β\beta is S(β)=D ω⊥(β)S(\beta) = D\,\omega^\perp(\beta). The ray with the fan angle γ\gamma is the line (θ,s)=(β+γ,Dsin⁡γ)(\theta, s) = (\beta + \gamma, D\sin\gamma), and g(β,γ)=p(β+γ,Dsin⁡γ)g(\beta, \gamma) = p(\beta + \gamma, D\sin\gamma).

Throughout, f∈Cc2(R2)f \in C^2_c(\mathbb{R}^2) has its support in the disk ∣x∣≤r|x| \le r with r<Dr < D, and xx is a point with ∣x∣<D|x| < D. We write ℓ(β)\ell(\beta) and γ′(β)\gamma'(\beta) for the distance from S(β)S(\beta) to xx and the fan angle of the ray through xx:

ℓcos⁡γ′=D−x⋅ω⊥(β),ℓsin⁡γ′=x⋅ω(β).\ell\cos\gamma' = D - x\cdot\omega^\perp(\beta), \qquad \ell\sin\gamma' = x\cdot\omega(\beta).

The page calls ℓ\ell by the name LL.

The proof has five parts. Part 1 writes the parallel-beam inversion formula with a finite-part integral, which is an honest function integral. Part 2 is a lemma on how a finite part behaves under a change of the cut. Part 3 changes the variables from parallel to fan coordinates and proves the fan-beam formula for both detectors. Part 4 proves the short-scan formula with Parker's weights. Part 5 names the approximations of the discrete algorithm.

Part 1. The ramp filter as a finite part

Let hh be the ramp filter, the distribution with the Fourier transform ∣σ∣|\sigma|. For q∈Cc2(R)q \in C^2_c(\mathbb{R}) put

(h∗q)(s)=−12π2∫0∞q(s+v)+q(s−v)−2q(s)v2 dv.(h * q)(s) = -\frac{1}{2\pi^2}\int_0^\infty \frac{q(s + v) + q(s - v) - 2q(s)}{v^2}\,dv.

The integrand is bounded near v=0v = 0, because q(s+v)+q(s−v)−2q(s)=O(v2)q(s + v) + q(s - v) - 2q(s) = O(v^2), and it is O(v−2)O(v^{-2}) at infinity. So the integral converges. For q(s)=e2πiσsq(s) = e^{2\pi i \sigma s} the numerator is 2e2πiσs(cos⁡(2πσv)−1)2e^{2\pi i\sigma s}(\cos(2\pi\sigma v) - 1), and ∫0∞(cos⁡(cv)−1)v−2 dv=−π∣c∣/2\int_0^\infty (\cos(cv) - 1)v^{-2}\,dv = -\pi|c|/2. So the formula multiplies e2πiσse^{2\pi i\sigma s} by ∣σ∣|\sigma|, and by Fourier inversion it is the ramp filter on Cc2C^2_c. The theorem of the page filtered back-projection gives

f(x)=∫0π(h∗p(θ,⋅))(x⋅ω(θ)) dθ=12∫02π(h∗p(θ,⋅))(x⋅ω(θ)) dθ.(1)f(x) = \int_0^\pi (h * p(\theta, \cdot))(x\cdot\omega(\theta))\,d\theta = \frac{1}{2}\int_0^{2\pi} (h * p(\theta, \cdot))(x\cdot\omega(\theta))\,d\theta. \tag{1}

The second form holds because p(θ+π,−s)=p(θ,s)p(\theta + \pi, -s) = p(\theta, s) and h∗qh * q commutes with the reflection s↦−ss \mapsto -s.

For ϵ>0\epsilon > 0 the integral in the definition splits as

(h∗q)(s)=−12π2lim⁡ϵ→0(∫∣s−u∣>ϵq(u)(s−u)2 du−2q(s)ϵ),(2)(h * q)(s) = -\frac{1}{2\pi^2}\lim_{\epsilon \to 0}\left(\int_{|s - u| > \epsilon} \frac{q(u)}{(s - u)^2}\,du - \frac{2q(s)}{\epsilon}\right), \tag{2}

since ∫ϵ∞2q(s)v−2 dv=2q(s)/ϵ\int_\epsilon^\infty 2q(s)v^{-2}\,dv = 2q(s)/\epsilon. The error of the bracket against its limit is at most ϵsup⁡∣q′′∣\epsilon \sup|q''|.

Part 2. A lemma on the cut

Lemma 1. Let ψ\psi be a function on an interval II with a Lipschitz derivative, with compact support in II, let t0t_0 be inside II, and let cc be a positive C2C^2 function on II. Then, as ϵ→0\epsilon \to 0,

∫{t∈I : c(t)∣t−t0∣>ϵ}ψ(t)(t−t0)2 dt=2c(t0)ψ(t0)ϵ+FP ⁣∫ψ(t)(t−t0)2 dt+O(ϵ),\int_{\{t \in I \,:\, c(t)|t - t_0| > \epsilon\}} \frac{\psi(t)}{(t - t_0)^2}\,dt = \frac{2c(t_0)\psi(t_0)}{\epsilon} + \mathrm{FP}\!\int \frac{\psi(t)}{(t - t_0)^2}\,dt + O(\epsilon),

where FP∫ψ(t)(t−t0)−2 dt=∫0∞(ψ(t0+v)+ψ(t0−v)−2ψ(t0))v−2 dv\mathrm{FP}\int \psi(t)(t - t_0)^{-2}\,dt = \int_0^\infty (\psi(t_0 + v) + \psi(t_0 - v) - 2\psi(t_0))v^{-2}\,dv. The constant in O(ϵ)O(\epsilon) depends only on bounds for ψ\psi, its Lipschitz constant, 1/c1/c and the first two derivatives of cc near t0t_0.

Proof. For small ϵ\epsilon the set where c(t)∣t−t0∣≤ϵc(t)|t - t_0| \le \epsilon near t0t_0 is an interval [t0−e−,t0+e+][t_0 - e_-, t_0 + e_+], where e± c(t0±e±)=ϵe_\pm\,c(t_0 \pm e_\pm) = \epsilon. Put c0=c(t0)c_0 = c(t_0) and c1=c′(t0)c_1 = c'(t_0). Taylor expansion gives e±=ϵ/c0∓c1ϵ2/c03+O(ϵ3)e_\pm = \epsilon/c_0 \mp c_1\epsilon^2/c_0^3 + O(\epsilon^3), so e++e−=2e+O(ϵ3)e_+ + e_- = 2e + O(\epsilon^3) with e=ϵ/c0e = \epsilon/c_0. The left side is

∫e+∞ψ(t0+v)v2 dv+∫e−∞ψ(t0−v)v2 dv=∫e∞ψ(t0+v)+ψ(t0−v)v2 dv−∫ee+ψ(t0+v)v2 dv−∫ee−ψ(t0−v)v2 dv.\int_{e_+}^\infty \frac{\psi(t_0 + v)}{v^2}\,dv + \int_{e_-}^\infty \frac{\psi(t_0 - v)}{v^2}\,dv = \int_e^\infty \frac{\psi(t_0 + v) + \psi(t_0 - v)}{v^2}\,dv - \int_e^{e_+} \frac{\psi(t_0 + v)}{v^2}\,dv - \int_e^{e_-} \frac{\psi(t_0 - v)}{v^2}\,dv.

The last two integrals are over intervals of length O(ϵ2)O(\epsilon^2) where v−2=e−2(1+O(ϵ))v^{-2} = e^{-2}(1 + O(\epsilon)) and ψ=ψ(t0)+O(ϵ)\psi = \psi(t_0) + O(\epsilon). Their sum is ψ(t0)(e++e−−2e)/e2+O(ϵ)=O(ϵ)\psi(t_0)(e_+ + e_- - 2e)/e^2 + O(\epsilon) = O(\epsilon). The first integral is 2ψ(t0)/e2\psi(t_0)/e plus ∫e∞(ψ(t0+v)+ψ(t0−v)−2ψ(t0))v−2 dv\int_e^\infty (\psi(t_0 + v) + \psi(t_0 - v) - 2\psi(t_0))v^{-2}\,dv. The integrand of the last integral is bounded, so it differs from the full finite part by O(e)=O(ϵ)O(e) = O(\epsilon). Since 2ψ(t0)/e=2c0ψ(t0)/ϵ2\psi(t_0)/e = 2c_0\psi(t_0)/\epsilon, the lemma follows. □\square

The point of the lemma is that a cut which is not symmetric to first order still gives the same finite part, and only the size of the singular term changes.

Part 3. The fan-beam formula

Let tt be a detector coordinate: t=γt = \gamma for the equiangular detector, or t=Dtan⁡γt = D\tan\gamma for the flat detector. In both cases γ\gamma is a smooth increasing function of tt on the range of tt, and the map

Φ:(β,t)↦(θ,s)=(β+γ(t), Dsin⁡γ(t))\Phi: (\beta, t) \mapsto (\theta, s) = (\beta + \gamma(t),\ D\sin\gamma(t))

from [0,2π)×T[0, 2\pi) \times T to [0,2π)×(−D,D)[0, 2\pi) \times (-D, D), with θ\theta taken modulo 2π2\pi, is a bijection. Given (θ,s)(\theta, s), the only solution is γ=arcsin⁡(s/D)\gamma = \arcsin(s/D) and β=θ−γ\beta = \theta - \gamma. Its Jacobian is J=Dcos⁡γ γ′(t)J = D\cos\gamma\,\gamma'(t), where γ′(t)\gamma'(t) is the derivative of γ\gamma in tt. The lines with ∣s∣≥D|s| \ge D miss the support of ff, so they add nothing to (1).

Lemma 2 (the distance to the ray). x⋅ω(β+γ)−Dsin⁡γ=ℓsin⁡(γ′−γ)x\cdot\omega(\beta + \gamma) - D\sin\gamma = \ell\sin(\gamma' - \gamma).

Proof. Expand ω(β+γ)=cos⁡γ ω(β)+sin⁡γ ω⊥(β)\omega(\beta + \gamma) = \cos\gamma\,\omega(\beta) + \sin\gamma\,\omega^\perp(\beta). Then x⋅ω(β+γ)−Dsin⁡γ=cos⁡γ (x⋅ω(β))−sin⁡γ (D−x⋅ω⊥(β))=ℓ(sin⁡γ′cos⁡γ−cos⁡γ′sin⁡γ)x\cdot\omega(\beta + \gamma) - D\sin\gamma = \cos\gamma\,(x\cdot\omega(\beta)) - \sin\gamma\,(D - x\cdot\omega^\perp(\beta)) = \ell(\sin\gamma'\cos\gamma - \cos\gamma'\sin\gamma). □\square

So x⋅ω(θ)−s=c(β,t) (tx−t)x\cdot\omega(\theta) - s = c(\beta, t)\,(t_x - t) with a positive smooth factor cc, where tx=tx(β)t_x = t_x(\beta) is the detector coordinate of the ray through xx. For the equiangular detector, tx=γ′t_x = \gamma' and c=ℓsin⁡(γ′−γ)/(γ′−γ)c = \ell\sin(\gamma' - \gamma)/(\gamma' - \gamma), with c=ℓc = \ell at γ=γ′\gamma = \gamma'. For the flat detector, sin⁡(γ′−γ)=cos⁡γ′cos⁡γ (tan⁡γ′−tan⁡γ)\sin(\gamma' - \gamma) = \cos\gamma'\cos\gamma\,(\tan\gamma' - \tan\gamma), and with U=(D−x⋅ω⊥(β))/D=ℓcos⁡γ′/DU = (D - x\cdot\omega^\perp(\beta))/D = \ell\cos\gamma'/D and tx=D x⋅ω(β)/(D−x⋅ω⊥(β))t_x = D\,x\cdot\omega(\beta)/(D - x\cdot\omega^\perp(\beta)) this gives c=DU/D2+t2c = DU/\sqrt{D^2 + t^2}.

Lemma 3 (the angle of the ray through xx). The direction θx(β)=β+γ′(β)\theta_x(\beta) = \beta + \gamma'(\beta) of the ray through xx satisfies θx′=J/c\theta_x' = J/c at t=txt = t_x, and θx′>0\theta_x' > 0.

Proof. Put ϕ(β,t)=x⋅ω(θ)−s\phi(\beta, t) = x\cdot\omega(\theta) - s with (θ,s)=Φ(β,t)(\theta, s) = \Phi(\beta, t), so ϕ=c (tx−t)\phi = c\,(t_x - t). The map (β,t)↦(θ,ϕ)(\beta, t) \mapsto (\theta, \phi) is Φ\Phi followed by (θ,s)↦(θ,x⋅ω(θ)−s)(\theta, s) \mapsto (\theta, x\cdot\omega(\theta) - s), whose Jacobian is −1-1. So its Jacobian is −J-J. On the curve t=tx(β)t = t_x(\beta) we have ϕ=0\phi = 0, ∂tϕ=−c\partial_t\phi = -c, and ∂βϕ+∂tϕ tx′=0\partial_\beta\phi + \partial_t\phi\,t_x' = 0, so ∂βϕ=c tx′\partial_\beta\phi = c\,t_x'. Then det⁡∂(θ,ϕ)/∂(β,t)=∂βθ ∂tϕ−∂tθ ∂βϕ=−c (∂βθ+∂tθ tx′)=−c θx′\det \partial(\theta, \phi)/\partial(\beta, t) = \partial_\beta\theta\,\partial_t\phi - \partial_t\theta\,\partial_\beta\phi = -c\,(\partial_\beta\theta + \partial_t\theta\,t_x') = -c\,\theta_x'. Hence J=c θx′J = c\,\theta_x'. Both JJ and cc are positive. □\square

The lemma also has a direct meaning. The source moves with the speed DD, and the part of its velocity normal to the ray is Dcos⁡γ′D\cos\gamma'. The ray turns about xx at the rate Dcos⁡γ′/ℓD\cos\gamma'/\ell, and this is J/cJ/c for the equiangular detector.

Theorem 1 (fan-beam inversion). With the notation above, put ψ(β,t)=g(β,γ(t)) J(t)/c(β,t)2\psi(\beta, t) = g(\beta, \gamma(t))\,J(t)/c(\beta, t)^2. Then

f(x)=12∫02π(h∗ψ(β,⋅))(tx(β)) dβ.f(x) = \frac{1}{2}\int_0^{2\pi} (h * \psi(\beta, \cdot))(t_x(\beta))\,d\beta.

For the equiangular detector this is

f(x)=∫02π1ℓ2∫κ(γ′−γ) Dcos⁡γ g(β,γ) dγ dβ,κ(u)=12(usin⁡u)2h(u),f(x) = \int_0^{2\pi} \frac{1}{\ell^2}\int \kappa(\gamma' - \gamma)\,D\cos\gamma\,g(\beta, \gamma)\,d\gamma\,d\beta, \qquad \kappa(u) = \frac{1}{2}\left(\frac{u}{\sin u}\right)^2 h(u),

and for the flat detector it is

f(x)=12∫02π1U2∫h(tx−t) DD2+t2 g(β,t) dt dβ.f(x) = \frac{1}{2}\int_0^{2\pi} \frac{1}{U^2}\int h(t_x - t)\,\frac{D}{\sqrt{D^2 + t^2}}\,g(\beta, t)\,dt\,d\beta.

Here the inner integrals mean the action of the distribution hh, given by the finite part of Part 1, on a function with a Lipschitz derivative.

Proof. Put (2) into (1) and move the limit outside, which is allowed because the error in (2) is uniform in θ\theta:

f(x)=−14π2lim⁡ϵ→0(∬∣x⋅ω−s∣>ϵp(θ,s)(x⋅ω−s)2 ds dθ−2ϵ∫02πp(θ,x⋅ω(θ)) dθ).f(x) = -\frac{1}{4\pi^2}\lim_{\epsilon \to 0}\left(\iint_{|x\cdot\omega - s| > \epsilon} \frac{p(\theta, s)}{(x\cdot\omega - s)^2}\,ds\,d\theta - \frac{2}{\epsilon}\int_0^{2\pi} p(\theta, x\cdot\omega(\theta))\,d\theta\right).

In the first integral the integrand is bounded on the domain, so the change of variables Φ\Phi is allowed. It gives

∫02π∫c ∣tx−t∣>ϵg(β,γ(t)) Jc2 (tx−t)2 dt dβ=∫02π∫c ∣tx−t∣>ϵψ(β,t)(t−tx)2 dt dβ.\int_0^{2\pi}\int_{c\,|t_x - t| > \epsilon} \frac{g(\beta, \gamma(t))\,J}{c^2\,(t_x - t)^2}\,dt\,d\beta = \int_0^{2\pi}\int_{c\,|t_x - t| > \epsilon} \frac{\psi(\beta, t)}{(t - t_x)^2}\,dt\,d\beta.

By Lemma 1, applied for each β\beta with bounds uniform in β\beta, the inner integral is 2cψ/ϵ+FP∫ψ (t−tx)−2 dt+O(ϵ)2c\psi/\epsilon + \mathrm{FP}\int\psi\,(t - t_x)^{-2}\,dt + O(\epsilon) with cψ=gJ/cc\psi = gJ/c taken at t=txt = t_x. In the second integral substitute θ=θx(β)\theta = \theta_x(\beta). By Lemma 3 this map is increasing, it covers [0,2π)[0, 2\pi) once modulo 2π2\pi, and dθ=(J/c) dβd\theta = (J/c)\,d\beta. Also p(θx,x⋅ω(θx))=g(β,γ(tx))p(\theta_x, x\cdot\omega(\theta_x)) = g(\beta, \gamma(t_x)), because both are the integral over the ray through xx. So

2ϵ∫02πp(θ,x⋅ω(θ)) dθ=2ϵ∫02πgJc∣t=tx dβ,\frac{2}{\epsilon}\int_0^{2\pi} p(\theta, x\cdot\omega(\theta))\,d\theta = \frac{2}{\epsilon}\int_0^{2\pi} \left.\frac{gJ}{c}\right|_{t = t_x}\,d\beta,

which cancels the singular term of Lemma 1. What remains is f(x)=−14π2∫02πFP∫ψ(β,t)(t−tx)−2 dt dβf(x) = -\frac{1}{4\pi^2}\int_0^{2\pi}\mathrm{FP}\int\psi(\beta, t)(t - t_x)^{-2}\,dt\,d\beta, and −12π2FP-\frac{1}{2\pi^2}\mathrm{FP} is h∗h * by Part 1. This is the first formula.

For the equiangular detector, J=Dcos⁡γJ = D\cos\gamma and 1/c2=ℓ−2w(γ′−γ)1/c^2 = \ell^{-2}w(\gamma' - \gamma) with w(u)=(u/sin⁡u)2w(u) = (u/\sin u)^2, a smooth even function with w(0)=1w(0) = 1. So ψ=ℓ−2w(γ′−γ) Dcos⁡γ g\psi = \ell^{-2}w(\gamma' - \gamma)\,D\cos\gamma\,g. Since ℓ\ell does not depend on γ\gamma and ww is smooth, h∗ψh * \psi at γ′\gamma' is ℓ−2\ell^{-2} times the action of the distribution whw h on Dcos⁡γ gD\cos\gamma\,g, and 12wh=κ\frac{1}{2}wh = \kappa. For the flat detector, γ(t)=arctan⁡(t/D)\gamma(t) = \arctan(t/D), so J=Dcos⁡γ⋅D/(D2+t2)=D3/(D2+t2)3/2J = D\cos\gamma \cdot D/(D^2 + t^2) = D^3/(D^2 + t^2)^{3/2} and J/c2=D/(U2D2+t2)J/c^2 = D/(U^2\sqrt{D^2 + t^2}). Here UU does not depend on tt. □\square

The second formula is the one that lines L4 and L5 of the algorithm compute. Line L4 forms Dcos⁡γ gD\cos\gamma\,g, line L5 applies the kernel κ\kappa, and line L8 divides by ℓ2\ell^2, the squared distance from the source. The function fan_beam_fbp_flat computes the third formula with the kernel h/2h/2.

Part 4. Short scan with Parker's weights

The ray (β,γ)(\beta, \gamma) and the ray (β+π+2γ,−γ)(\beta + \pi + 2\gamma, -\gamma) are the same line, because (β+π+2γ)+(−γ)=(β+γ)+π(\beta + \pi + 2\gamma) + (-\gamma) = (\beta + \gamma) + \pi and Dsin⁡(−γ)=−Dsin⁡γD\sin(-\gamma) = -D\sin\gamma.

Lemma 4 (weights). Let W(θ,s)W(\theta, s) be a function with a Lipschitz derivative and W(θ,s)+W(θ+π,−s)=1W(\theta, s) + W(\theta + \pi, -s) = 1 on the support of pp. Then f(x)=∫02π(h∗(Wp)(θ,⋅))(x⋅ω(θ)) dθf(x) = \int_0^{2\pi} (h * (W p)(\theta, \cdot))(x\cdot\omega(\theta))\,d\theta.

Proof. Split [0,2π)[0, 2\pi) into [0,π)[0, \pi) and [π,2π)[\pi, 2\pi) and substitute θ↦θ+π\theta \mapsto \theta + \pi in the second part. Since hh is even, (h∗(Wp)(θ+π,⋅))(−x⋅ω(θ))=∫h(x⋅ω−s) W(θ+π,−s) p(θ,s) ds(h * (Wp)(\theta + \pi, \cdot))(-x\cdot\omega(\theta)) = \int h(x\cdot\omega - s)\,W(\theta + \pi, -s)\,p(\theta, s)\,ds. The two parts add to ∫0π(h∗p(θ,⋅))(x⋅ω) dθ\int_0^\pi (h * p(\theta, \cdot))(x\cdot\omega)\,d\theta, which is f(x)f(x) by (1). □\square

Lemma 5 (Parker's weights add to 1). Let 0<δ<π/20 < \delta < \pi/2 and ∣γ∣<δ|\gamma| < \delta. Define w(β,γ)w(\beta, \gamma) for β∈[0,π+2δ]\beta \in [0, \pi + 2\delta] by sin⁡2(π4βδ−γ)\sin^2(\frac{\pi}{4}\frac{\beta}{\delta - \gamma}) for β<2(δ−γ)\beta < 2(\delta - \gamma), by 1 for 2(δ−γ)≤β≤π−2γ2(\delta - \gamma) \le \beta \le \pi - 2\gamma, and by sin⁡2(π4π+2δ−βδ+γ)\sin^2(\frac{\pi}{4}\frac{\pi + 2\delta - \beta}{\delta + \gamma}) for β>π−2γ\beta > \pi - 2\gamma, and put w=0w = 0 for the other β\beta modulo 2π2\pi. Then the weights of the two copies of each line add to 1.

Proof. There are three cases. If β<2(δ−γ)\beta < 2(\delta - \gamma), the copy β∗=β+π+2γ\beta^* = \beta + \pi + 2\gamma lies in (π+2γ,π+2δ)(\pi + 2\gamma, \pi + 2\delta), which is the last region for the fan angle −γ-\gamma. Its weight is sin⁡2(π42(δ−γ)−βδ−γ)=cos⁡2(π4βδ−γ)\sin^2(\frac{\pi}{4}\frac{2(\delta - \gamma) - \beta}{\delta - \gamma}) = \cos^2(\frac{\pi}{4}\frac{\beta}{\delta - \gamma}), and the sum is 1. If 2(δ−γ)≤β≤π−2γ2(\delta - \gamma) \le \beta \le \pi - 2\gamma, then β+π+2γ≥π+2δ\beta + \pi + 2\gamma \ge \pi + 2\delta and β−π+2γ≤0\beta - \pi + 2\gamma \le 0, so the other copy is outside the scan or on its edge, where the weight is 0. If β>π−2γ\beta > \pi - 2\gamma, the copy β∗=β−π+2γ\beta^* = \beta - \pi + 2\gamma lies in (0,2(δ+γ)](0, 2(\delta + \gamma)], the first region for −γ-\gamma, and its argument and the argument of w(β,γ)w(\beta, \gamma) add to π4⋅2δ+2γδ+γ=π2\frac{\pi}{4}\cdot\frac{2\delta + 2\gamma}{\delta + \gamma} = \frac{\pi}{2}. Again the sum is 1. □\square

The weight is continuous with a continuous derivative in β\beta. The derivative of sin⁡2(π4u)\sin^2(\frac{\pi}{4}u) at u=0u = 0 and u=2u = 2 is 0, which joins the pieces. If the support of ff lies in ∣x∣≤r|x| \le r with Dsin⁡δ>rD\sin\delta > r, only fan angles with ∣γ∣≤arcsin⁡(r/D)<δ|\gamma| \le \arcsin(r/D) < \delta carry data, and there the weight has a Lipschitz derivative in (β,γ)(\beta, \gamma).

Theorem 2 (short scan). Under these conditions,

f(x)=∫0π+2δ1ℓ2∫2κ(γ′−γ) Dcos⁡γ w(β,γ) g(β,γ) dγ dβ.f(x) = \int_0^{\pi + 2\delta} \frac{1}{\ell^2}\int 2\kappa(\gamma' - \gamma)\,D\cos\gamma\,w(\beta, \gamma)\,g(\beta, \gamma)\,d\gamma\,d\beta.

Proof. Take WW as the Parker weight, written in parallel coordinates through Φ\Phi. Lemma 5 gives the hypothesis of Lemma 4. Then repeat Part 3 with WpWp in place of pp and without the factor 12\frac{1}{2} of (1). The weight is 0 for β∉[0,π+2δ]\beta \notin [0, \pi + 2\delta]. □\square

This is the factor 2 that the function _angles returns for the short scan.

Part 5. What the discrete algorithm approximates

Line L2 replaces hh by the ramp band-limited to 1/(2α)1/(2\alpha) and sampled at mαm\alpha, which gives the values κ(mα)=12(mα/sin⁡mα)2hB(mα)\kappa(m\alpha) = \frac{1}{2}(m\alpha/\sin m\alpha)^2 h_B(m\alpha): 1/(8α2)1/(8\alpha^2) at m=0m = 0, 0 at even mm, and −1/(2π2sin⁡2(mα))-1/(2\pi^2\sin^2(m\alpha)) at odd mm. The values come from Lemma 2 of the filtered back-projection proof. Line L5 replaces the integral over γ\gamma by the sum with step α\alpha, line L8 reads the filtered projection at γ′\gamma' by linear interpolation, and line L9 replaces the integral over β\beta by the rectangle rule with step 2π/a2\pi/a. For a full scan the integrand is periodic in β\beta, so this is the trapezoidal rule. These are the only approximations. They are the same as in parallel-beam FBP, with one difference: the factor (u/sin⁡u)2(u/\sin u)^2 makes the band limit in γ\gamma only approximately a band limit in ss, so Lemma 3 of the parallel proof (exact discrete filtering) does not carry over exactly. The page reports the error of these approximations as a measurement.

Complexity

In the real-RAM model:

  • Line L2 takes O(d)O(d).
  • Lines L3 to L5 take O(d2)O(d^2) for each source with the direct sum, or O(dlog⁡d)O(d \log d) with an FFT of length at least 2d−12d - 1, so O(ad2)O(a d^2) or O(adlog⁡d)O(a d \log d) in total.
  • Lines L6 to L8 take O(1)O(1) for each source and pixel, so O(an2)O(a n^2).

The total is O(adlog⁡d+an2)O(a d \log d + a n^2) time with an FFT and O(ad2+an2)O(a d^2 + a n^2) with the direct sum, which the code uses. The extra space is O(ad+n2)O(a d + n^2) for the filtered projections and the image. This is the same order as parallel-beam FBP. The weight 1/L21/L^2 and the angle γ′\gamma' cost a few more operations per pixel than the parallel back-projection.

Properties

  • Linear. The output is a linear function of the fan data, as the code tests.
  • Exact in the limit. The continuous formula is exact for a smooth ff supported inside the scan circle. The only errors come from the band limit and the sampling.
  • Not shift-invariant in the back-projection. The weight 1/L21/L^2 depends on the pixel and the source, so the noise and the resolution vary across the image more than with parallel FBP.
  • Redundant full scan. A full scan measures each line twice. The two copies add with the weight 12\frac{1}{2} each, which is the 12\frac{1}{2} inside κ\kappa.
  • Not local. As in parallel FBP, the kernel decays like 1/γ21/\gamma^2 and does not vanish, so a truncated detector gives errors everywhere (interior tomography).

Variants and improvements

  • Rebinning. Fan-to-parallel rebinning interpolates the fan data to parallel rays and then runs parallel FBP. The back-projection has no 1/L21/L^2 weight, but the interpolation smooths the data.
  • Flat detector. The formula with t=Dtan⁡γt = D\tan\gamma uses the plain ramp h/2h/2 and the weight D/D2+t2D/\sqrt{D^2 + t^2}. This is the 2D case of the Feldkamp-Davis-Kress algorithm.
  • Short scan. Parker's weights reduce the scan to π\pi plus the fan angle. Other smooth weights with the same sum rule also work, and the proof covers all of them.
  • Windows. Multiply the ramp by a window function to reduce noise at the cost of resolution, as in parallel FBP.
  • Iterative methods. SART and SIRT take any ray geometry, including fan beams, and handle few views better.

When to use it

Use it for 2D CT with a fan-beam scanner, a full scan or a short scan, and an untruncated detector. It works on the data as the scanner records it, with no interpolation before the filter. If the data is rebinned anyway for other reasons, or if a parallel FBP code is at hand, rebinning is simpler. For a cone of rays in 3D, use Feldkamp-Davis-Kress for a circular scan or Katsevich's algorithm for a helical scan.

Pitfalls

  • The wrong kernel. The kernel in γ\gamma is not the parallel ramp. Using hB(mα)h_B(m\alpha) in place of κ(mα)\kappa(m\alpha) drops the factor (u/sin⁡u)2(u/\sin u)^2 and the 12\frac{1}{2}. The scale is then wrong by a factor 2, and the shape of the kernel is wrong away from its center.
  • Missing 1/L21/L^2. Without the distance weight, each view adds its smear with the wrong weight, and the weight error depends on the pixel. The image is then off by a factor that varies across the image.
  • Short scan without weights. A scan over π+2δ\pi + 2\delta counts some lines twice and others once. The proof needs weights whose values on the two copies of each line add to 1. Weights that jump from 0 to 1 satisfy the sum rule, but the ramp filter turns a jump in the data into a long tail, so the discrete result is worse. Parker's weights change smoothly.
  • Weights in the wrong convention. Parker's formulas depend on the sign of γ\gamma and on the start angle. Check the sum rule w(β,γ)+w(β+π+2γ,−γ)=1w(\beta, \gamma) + w(\beta + \pi + 2\gamma, -\gamma) = 1 in the geometry of the code, as the test does.
  • Center of rotation. The central ray must hit the detector at the position (d−1)/2(d-1)/2. An offset of a fraction of a bin gives ring-like blur, as in parallel FBP.

Implementations

Each implementation follows the pseudocode above. A comment @line links a line of code to a line of the pseudocode. Point at a line of the pseudocode to see the matching code. The build runs the native tests of each language.

fan_beam_filtered_back_projection.pyI0RawGitHub
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/fan-beam-filtered-back-projection/. The authors are listed in prov/2Y6GKS.jsonl.
"""Fan-beam filtered back-projection for an equiangular and a flat detector.

Conventions:
- omega(t) = (cos t, sin t) and omega_perp(t) = (-sin t, cos t). The Radon
  transform is R f(theta, s) = integral f(s omega(theta) + t omega_perp(theta)) dt.
- The source at angle beta is S(beta) = D omega_perp(beta), at the distance D
  from the center of rotation. The ray at the fan angle gamma leaves S(beta)
  in the direction -omega_perp(beta + gamma). It is the line with
  theta = beta + gamma and s = D sin gamma, so its line integral is
  g(beta, gamma) = R f(beta + gamma, D sin gamma).
- Equiangular detector: column j has the fan angle
  gamma_j = (j - (d - 1) / 2) alpha.
- Flat detector: a virtual line detector through the center, normal to the
  central ray. Column j sits at t_j = (j - (d - 1) / 2) tau, and its ray has
  the fan angle atan(t_j / D).
- Full scan: beta_k = 2 pi k / a, k = 0 .. a - 1. Short scan: beta_k = k
  (pi + 2 delta) / a with Parker weights, delta the half fan angle.
- The output is an n x n image on [-1, 1]^2. Pixel (i, j) has its center at
  x_j = -1 + (2 j + 1) / n and y_i = 1 - (2 i + 1) / n, so y goes up.
"""

import math


def ram_lak(m, tau):
    """h(m tau) of the ramp filter |sigma| band-limited to 1 / (2 tau)."""
    if m == 0:
        return 1.0 / (4.0 * tau * tau)
    if m % 2 == 0:
        return 0.0
    return -1.0 / (m * m * math.pi * math.pi * tau * tau)


def fan_kernel(d, alpha):
    """kappa(m alpha) = (1/2) (m alpha / sin(m alpha))^2 h(m alpha), m = -(d - 1) .. d - 1.

    Entry m + d - 1 holds kappa(m alpha): 1 / (8 alpha^2) at m = 0, 0 at even
    m, and -1 / (2 pi^2 sin^2(m alpha)) at odd m.
    """
    out = []
    for m in range(-(d - 1), d):
        if m == 0:
            out.append(1.0 / (8.0 * alpha * alpha))
        elif m % 2 == 0:
            out.append(0.0)
        else:
            out.append(-1.0 / (2.0 * math.pi * math.pi * math.sin(m * alpha) ** 2))
    return out


def flat_kernel(d, tau):
    """h(m tau) / 2 with the Ram-Lak h, m = -(d - 1) .. d - 1."""
    return [0.5 * ram_lak(m, tau) for m in range(-(d - 1), d)]


def convolve(p, kern, step):
    """q_j = step * sum_l kern((j - l) step) p_l, the aperiodic convolution by a direct sum."""
    d = len(p)
    return [step * sum(kern[j - l + d - 1] * p[l] for l in range(d)) for j in range(d)]


def parker_weight(beta, gamma, delta):
    """Parker's short-scan weight for beta in [0, pi + 2 delta] and |gamma| <= delta.

    With the geometry above the ray (beta, gamma) and the ray
    (beta + pi + 2 gamma, -gamma) are the same line, and their weights add to 1.
    """
    if beta < 0.0 or beta > math.pi + 2.0 * delta:
        return 0.0
    if beta < 2.0 * (delta - gamma):
        return math.sin(0.25 * math.pi * beta / (delta - gamma)) ** 2
    if beta <= math.pi - 2.0 * gamma:
        return 1.0
    if delta + gamma <= 0.0:
        return 0.0
    return math.sin(0.25 * math.pi * (math.pi + 2.0 * delta - beta) / (delta + gamma)) ** 2


def source_coordinates(x, y, beta, dist):
    """(L cos gamma', L sin gamma') of the point (x, y) seen from the source S(beta).

    L is the distance from the source and gamma' the fan angle of the ray
    through the point: L cos gamma' = D - x.omega_perp(beta) and
    L sin gamma' = x.omega(beta).
    """
    c, s = math.cos(beta), math.sin(beta)
    return dist - (-x * s + y * c), x * c + y * s


def lin_interp(q, u):
    """The linear interpolation of q at the fractional index u, and 0 outside [0, len(q) - 1]."""
    b = math.floor(u)
    w = u - b
    val = 0.0
    if 0 <= b < len(q):
        val += (1.0 - w) * q[b]
    if 0 <= b + 1 < len(q):
        val += w * q[b + 1]
    return val


def _angles(a, scan, delta):
    if scan == "full":
        return [2.0 * math.pi * k / a for k in range(a)], 2.0 * math.pi / a, 1.0
    if scan == "short":
        span = math.pi + 2.0 * delta
        return [span * k / a for k in range(a)], span / a, 2.0
    raise ValueError("scan must be 'full' or 'short'")


def fan_beam_fbp(sino, dist, alpha, n, scan="full", delta=None):
    """Reconstruct an n x n image from equiangular fan-beam data.

    sino[k][j] = g(beta_k, gamma_j). For scan = "short" the angles cover
    [0, pi + 2 delta) and delta must be at least the largest |gamma_j|.
    """
    a, d = len(sino), len(sino[0])  # @line L1
    betas, dbeta, factor = _angles(a, scan, delta)
    kern = fan_kernel(d, alpha)  # @line L2
    c0 = (d - 1) / 2.0
    gammas = [(j - c0) * alpha for j in range(d)]
    qs = []
    for k in range(a):  # @line L3
        w = [1.0] * d
        if scan == "short":
            w = [parker_weight(betas[k], gm, delta) for gm in gammas]
        p = [dist * math.cos(gm) * wj * v for gm, wj, v in zip(gammas, w, sino[k])]  # @line L4
        qs.append(convolve(p, kern, alpha))  # @line L5
    xs = [-1.0 + (2 * j + 1) / n for j in range(n)]
    ys = [1.0 - (2 * i + 1) / n for i in range(n)]
    img = [[0.0] * n for _ in range(n)]
    for k in range(a):
        q, beta = qs[k], betas[k]
        for i, y in enumerate(ys):  # @line L6
            row = img[i]
            for j, x in enumerate(xs):
                lc, ls = source_coordinates(x, y, beta, dist)  # @line L7
                gam = math.atan2(ls, lc)
                row[j] += lin_interp(q, gam / alpha + c0) / (lc * lc + ls * ls)  # @line L8
    w = factor * dbeta
    return [[w * v for v in row] for row in img]  # @line L9


def fan_beam_fbp_flat(sino, dist, tau, n, scan="full", delta=None):
    """Reconstruct an n x n image from fan-beam data on a flat detector.

    sino[k][j] = g(beta_k, atan(t_j / D)) with t_j = (j - (d - 1) / 2) tau on
    the virtual detector through the center.
    """
    a, d = len(sino), len(sino[0])
    betas, dbeta, factor = _angles(a, scan, delta)
    kern = flat_kernel(d, tau)
    c0 = (d - 1) / 2.0
    ts = [(j - c0) * tau for j in range(d)]
    qs = []
    for k in range(a):
        w = [1.0] * d
        if scan == "short":
            w = [parker_weight(betas[k], math.atan(t / dist), delta) for t in ts]
        p = [dist / math.sqrt(dist * dist + t * t) * wj * v for t, wj, v in zip(ts, w, sino[k])]
        qs.append(convolve(p, kern, tau))
    xs = [-1.0 + (2 * j + 1) / n for j in range(n)]
    ys = [1.0 - (2 * i + 1) / n for i in range(n)]
    img = [[0.0] * n for _ in range(n)]
    for k in range(a):
        q, beta = qs[k], betas[k]
        for i, y in enumerate(ys):
            row = img[i]
            for j, x in enumerate(xs):
                lc, ls = source_coordinates(x, y, beta, dist)
                u = lc / dist
                row[j] += lin_interp(q, (dist * ls / lc) / tau + c0) / (u * u)
    w = factor * dbeta
    return [[w * v for v in row] for row in img]
test_fan_beam_filtered_back_projection.py 150 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/fan-beam-filtered-back-projection/. The authors are listed in prov/2Y6GKS.jsonl.

import math
import random

from fan_beam_filtered_back_projection import (
    convolve,
    fan_beam_fbp,
    fan_beam_fbp_flat,
    fan_kernel,
    flat_kernel,
    parker_weight,
    ram_lak,
    source_coordinates,
)

DIST = 3.0
GAMMA_MAX = math.asin(math.sqrt(2.0) / DIST)  # the fan covers the disk of radius sqrt(2)
D = 49
ALPHA = 2.0 * GAMMA_MAX / (D - 1)
TAU_FLAT = 2.0 * DIST * math.tan(GAMMA_MAX) / (D - 1)
A = 64
N = 32
XS = [-1.0 + (2 * j + 1) / N for j in range(N)]
YS = [1.0 - (2 * i + 1) / N for i in range(N)]

# The modified Shepp-Logan phantom: rho, A, B, x0, y0, phi in degrees (Toft 1996, first five ellipses).
PHANTOM = [
    (1.0, 0.69, 0.92, 0.0, 0.0, 0.0),
    (-0.8, 0.6624, 0.874, 0.0, -0.0184, 0.0),
    (-0.2, 0.11, 0.31, 0.22, 0.0, -18.0),
    (-0.2, 0.16, 0.41, -0.22, 0.0, 18.0),
    (0.1, 0.21, 0.25, 0.0, 0.35, 0.0),
]


def ellipse_projection(table, theta, s):
    """The exact Radon transform of an ellipse table (Kak and Slaney, chapter 3)."""
    total = 0.0
    for rho, a, b, x0, y0, phi in table:
        t = theta - math.radians(phi)
        u = s - (x0 * math.cos(theta) + y0 * math.sin(theta))
        a2 = a * a * math.cos(t) ** 2 + b * b * math.sin(t) ** 2
        if u * u < a2:
            total += 2.0 * rho * a * b / a2 * math.sqrt(a2 - u * u)
    return total


def gauss_projection(theta, s):
    """R f for f(x) = exp(-4 pi |x|^2): (1/2) exp(-4 pi s^2) at every angle."""
    return 0.5 * math.exp(-4.0 * math.pi * s * s)


def fan_data(radon, betas, gammas):
    """g(beta, gamma) = R f(beta + gamma, D sin gamma)."""
    return [[radon(b + g, DIST * math.sin(g)) for g in gammas] for b in betas]


def gauss_error(img):
    return max(abs(img[i][j] - math.exp(-4.0 * math.pi * (XS[j] ** 2 + YS[i] ** 2))) for i in range(N) for j in range(N))


EQUI = [(j - (D - 1) / 2.0) * ALPHA for j in range(D)]
FULL = [2.0 * math.pi * k / A for k in range(A)]


def test_kernel_values() -> None:
    kern = fan_kernel(D, ALPHA)
    assert abs(kern[D - 1] - 1.0 / (8.0 * ALPHA * ALPHA)) < 1e-9
    for m in range(1, D):
        want = 0.5 * (m * ALPHA / math.sin(m * ALPHA)) ** 2 * ram_lak(m, ALPHA)
        assert abs(kern[D - 1 + m] - want) <= 1e-12 * abs(kern[D - 1])
        assert kern[D - 1 + m] == kern[D - 1 - m]
    assert flat_kernel(3, 0.5) == [0.5 * ram_lak(m, 0.5) for m in range(-2, 3)]
    assert convolve([1.0, 2.0], [3.0, 4.0, 5.0], 2.0) == [2.0 * (4.0 + 6.0), 2.0 * (5.0 + 8.0)]


def test_geometry_identity() -> None:
    # x . omega(beta + gamma) - D sin gamma = L sin(gamma' - gamma)
    rng = random.Random(1)
    for _ in range(200):
        x, y = rng.uniform(-1, 1), rng.uniform(-1, 1)
        beta, gamma = rng.uniform(0, 2 * math.pi), rng.uniform(-0.5, 0.5)
        lc, ls = source_coordinates(x, y, beta, DIST)
        big_l, gp = math.hypot(lc, ls), math.atan2(ls, lc)
        lhs = x * math.cos(beta + gamma) + y * math.sin(beta + gamma) - DIST * math.sin(gamma)
        assert abs(lhs - big_l * math.sin(gp - gamma)) < 1e-12


def test_conjugate_ray_is_the_same_line() -> None:
    rng = random.Random(2)
    for _ in range(100):
        beta, gamma = rng.uniform(0, 2 * math.pi), rng.uniform(-0.5, 0.5)
        b2, g2 = beta + math.pi + 2 * gamma, -gamma
        # same line: (theta, s) and (theta + pi, -s) describe one line
        assert abs(math.sin(b2 + g2 - (beta + gamma) - math.pi)) < 1e-12
        assert abs(DIST * math.sin(g2) + DIST * math.sin(gamma)) < 1e-12


def test_parker_weights_add_to_one() -> None:
    delta = GAMMA_MAX
    span = math.pi + 2 * delta
    rng = random.Random(3)
    for _ in range(2000):
        beta, gamma = rng.uniform(0, span), rng.uniform(-delta, delta)
        b2 = beta + math.pi + 2 * gamma
        if b2 > span:
            b2 -= 2 * math.pi
        w = parker_weight(beta, gamma, delta) + parker_weight(b2, -gamma, delta)
        assert abs(w - 1.0) < 1e-12
        assert 0.0 <= parker_weight(beta, gamma, delta) <= 1.0


def test_gaussian_full_scan() -> None:
    img = fan_beam_fbp(fan_data(gauss_projection, FULL, EQUI), DIST, ALPHA, N)
    assert gauss_error(img) < 0.03


def test_gaussian_short_scan() -> None:
    a = 40
    span = math.pi + 2 * GAMMA_MAX
    betas = [span * k / a for k in range(a)]
    img = fan_beam_fbp(fan_data(gauss_projection, betas, EQUI), DIST, ALPHA, N, scan="short", delta=GAMMA_MAX)
    assert gauss_error(img) < 0.03


def test_gaussian_flat_detector() -> None:
    gammas = [math.atan((j - (D - 1) / 2.0) * TAU_FLAT / DIST) for j in range(D)]
    img = fan_beam_fbp_flat(fan_data(gauss_projection, FULL, gammas), DIST, TAU_FLAT, N)
    assert gauss_error(img) < 0.03


def test_phantom_values() -> None:
    img = fan_beam_fbp(fan_data(lambda t, s: ellipse_projection(PHANTOM, t, s), FULL, EQUI), DIST, ALPHA, N)
    assert abs(img[16][16] - 0.2) < 0.03  # pixel (1/32, -1/32), true value 0.2
    assert abs(img[8][16] - 0.3) < 0.04  # pixel (1/32, 15/32), inside the top ellipse, true value 0.3


def test_linear_in_the_data() -> None:
    rng = random.Random(4)
    a, d, n = 8, 9, 8
    alpha = 0.05
    g1 = [[rng.uniform(-1, 1) for _ in range(d)] for _ in range(a)]
    g2 = [[rng.uniform(-1, 1) for _ in range(d)] for _ in range(a)]
    mix = [[2.0 * u - 3.0 * v for u, v in zip(r1, r2)] for r1, r2 in zip(g1, g2)]
    f1, f2, fm = (fan_beam_fbp(g, DIST, alpha, n) for g in (g1, g2, mix))
    for i in range(n):
        for j in range(n):
            assert abs(fm[i][j] - (2.0 * f1[i][j] - 3.0 * f2[i][j])) < 1e-9

History

CT scanners of the 1970s moved to fan beams, which need fewer motions than a parallel scan. One way to reconstruct is to rebin the fan data to parallel rays. Herman, Lakshminarayanan and Naparstek gave in 1976 a convolution method for divergent rays, which filters the fan data directly. The formula with the weight 1/L21/L^2 and the kernel κ\kappa is the form that Kak and Slaney derive for equiangular rays and for equally spaced collinear detectors in their Section 3.4. Parker gave his short-scan weights in 1982, with smooth ramps at both ends of the scan.

References

  1. G. T. Herman, A. V. Lakshminarayanan and A. Naparstek, Convolution reconstruction techniques for divergent beams, Computers in Biology and Medicine 6(4), 1976, pp. 259 to 271
  2. D. L. Parker, Optimal short scan convolution reconstruction for fan beam CT, Medical Physics 9(2), 1982, pp. 254 to 257 (the short-scan weights)
  3. A. C. Kak and M. Slaney, Principles of Computerized Tomographic Imaging, SIAM Classics in Applied Mathematics 33, 2001, Chapter 3, Section 3.4 (reconstruction from fan projections, equiangular rays and equally spaced collinear detectors) and Section 3.5 (a limited number of views)

Where this leads

About this page

The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.

LadderLevelWhat the next level needs
Human proofH1 sketch
  • a full proof of time.worst
  • a full proof of space.extra
LeanL0 no Lean part
  • name a Lean module in the lean field (07)
Code (python)I0 not checked yet
  • the tests did not run in this build
VisualV0 none
  • add viz/scene.ts or a figure (10)
WritingW2 basic
  • a scene preset for the example