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
- Model
- Real RAM
- Properties
- deterministicnot in placenot iterativelineariterative
- Evidence
- Proof sketchCode in 1 languages
- 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 , where is the distance from the source. With source positions, detector bins and an image it takes time with an FFT. A full scan of gives each line twice. A short scan of 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 is at , at the distance from the center of rotation, with and . The ray with the fan angle leaves in the direction . It is the line with and . So the fan data is
where 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 is zero outside a disk of radius .
An equiangular detector samples for . A flat detector samples on a line through the center normal to the central ray, and its ray has the fan angle . A full scan takes for . The output is an image on . Pixel has its center at and , so row 0 is at the top and goes up.
For a point and a source , let be the distance from the source to and the fan angle of the ray through :
The algorithm evaluates the fan-beam inversion formula
where is the ramp filter, the filter with the frequency response in ordinary frequency. The proof below derives it from the parallel formula.
The algorithm
FAN-FBP(g, D, α, n) ▷ g[k][j]: source angle β_k = 2πk/a, fan angle γ_j = (j - (d-1)/2) α- 1
a, d ← the number of rows and of columns of g - 2
κ[m] ← 1/(8α²) for m = 0, 0 for even m, -1/(2π² sin²(mα)) for odd m, m = -(d-1) .. d-1 - 3
for k ← 0 to a - 1 do - 4
p[j] ← D cos(γ_j) · g[k][j] for each j - 5
q_k[j] ← α Σ_l κ[j - l] p[l] for each j ▷ direct sum, or an FFT with zero padding to 2d - 1 - 6
for each pixel (i, j) with center x = (x_j, y_i) do - 7
for each k: (L cos γ', L sin γ') ← (D - x·ω⊥(β_k), x·ω(β_k)) - 8
f[i][j] ← Σ_k LININTERP(q_k, γ'/α + (d-1)/2) / L² - 9
return (2π/a) · f
Line L2 is the sampled kernel , where is the Ram-Lak kernel: the ramp cut off at the Nyquist frequency of the angular sampling. Since for odd , the factor cancels and only remains. Line L4 is the cosine weight. Line L5 is an aperiodic discrete convolution. Line L8 reads the filtered projection at the fan angle of the ray through the pixel, by linear interpolation with 0 outside the detector, and divides by . Line L9 multiplies by the angle step.
For a flat detector, line L4 uses the weight , line L2 uses with the spacing , and line L8 reads the filtered projection at and divides by with . The code has both versions.
Short scan. Each line is measured twice in a full scan: the ray and the ray are the same line. A scan over , with at least the half fan angle, measures every line at least once. Parker's weights are
and the weights of the two copies of each line add to 1. The short scan multiplies line L4 by , takes , and uses the factor 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 with density 1 and a source at . Use bins with and source positions. The ray with fan angle is at the distance from the center, and its line integral is . The disk is the same at each angle, so all four rows of are equal.
| quantity | values at |
|---|---|
| fan angle | -0.30, -0.15, 0, 0.15, 0.30 |
| data | 0, 0.8017, 1, 0.8017, 0 |
| weighted | 0, 1.5854, 2, 1.5854, 0 |
| filtered | -0.6031, 0.6406, 0.5877, 0.6406, -0.6031 |
The kernel values are , , , and 0 at the even offsets. So . At the center of the disk, and for every source, so line L8 gives and line L9 gives . 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 , a fan that covers the disk of radius (half fan angle ), bins with , and . These numbers are measurements of this setup, not bounds.
| scan and phantom | result |
|---|---|
| full scan, , Gaussian , largest error | 0.0179 |
| short scan with Parker's weights, over , same Gaussian | 0.0182 |
| full scan, flat detector, , same Gaussian | 0.0215 |
| full scan, modified Shepp-Logan phantom (first 5 ellipses), pixel , true 0.2 | 0.2097 |
| same, pixel 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 , with the ramp written as a finite-part integral. It changes the variables from to . The Jacobian of is , which gives the weight of line L4. The distance from to the ray is . The ramp kernel is homogeneous of degree , so . This gives both the factor and the kernel . 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. and . The Radon transform is , now for all , so that . The source at the angle is . The ray with the fan angle is the line , and .
Throughout, has its support in the disk with , and is a point with . We write and for the distance from to and the fan angle of the ray through :
The page calls by the name .
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 be the ramp filter, the distribution with the Fourier transform . For put
The integrand is bounded near , because , and it is at infinity. So the integral converges. For the numerator is , and . So the formula multiplies by , and by Fourier inversion it is the ramp filter on . The theorem of the page filtered back-projection gives
The second form holds because and commutes with the reflection .
For the integral in the definition splits as
since . The error of the bracket against its limit is at most .
Part 2. A lemma on the cut
Lemma 1. Let be a function on an interval with a Lipschitz derivative, with compact support in , let be inside , and let be a positive function on . Then, as ,
where . The constant in depends only on bounds for , its Lipschitz constant, and the first two derivatives of near .
Proof. For small the set where near is an interval , where . Put and . Taylor expansion gives , so with . The left side is
The last two integrals are over intervals of length where and . Their sum is . The first integral is plus . The integrand of the last integral is bounded, so it differs from the full finite part by . Since , the lemma follows.
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 be a detector coordinate: for the equiangular detector, or for the flat detector. In both cases is a smooth increasing function of on the range of , and the map
from to , with taken modulo , is a bijection. Given , the only solution is and . Its Jacobian is , where is the derivative of in . The lines with miss the support of , so they add nothing to (1).
Lemma 2 (the distance to the ray). .
Proof. Expand . Then .
So with a positive smooth factor , where is the detector coordinate of the ray through . For the equiangular detector, and , with at . For the flat detector, , and with and this gives .
Lemma 3 (the angle of the ray through ). The direction of the ray through satisfies at , and .
Proof. Put with , so . The map is followed by , whose Jacobian is . So its Jacobian is . On the curve we have , , and , so . Then . Hence . Both and are positive.
The lemma also has a direct meaning. The source moves with the speed , and the part of its velocity normal to the ray is . The ray turns about at the rate , and this is for the equiangular detector.
Theorem 1 (fan-beam inversion). With the notation above, put . Then
For the equiangular detector this is
and for the flat detector it is
Here the inner integrals mean the action of the distribution , 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 :
In the first integral the integrand is bounded on the domain, so the change of variables is allowed. It gives
By Lemma 1, applied for each with bounds uniform in , the inner integral is with taken at . In the second integral substitute . By Lemma 3 this map is increasing, it covers once modulo , and . Also , because both are the integral over the ray through . So
which cancels the singular term of Lemma 1. What remains is , and is by Part 1. This is the first formula.
For the equiangular detector, and with , a smooth even function with . So . Since does not depend on and is smooth, at is times the action of the distribution on , and . For the flat detector, , so and . Here does not depend on .
The second formula is the one that lines L4 and L5 of the algorithm compute. Line L4 forms , line L5 applies the kernel , and line L8 divides by , the squared distance from the source. The function fan_beam_fbp_flat computes the third formula with the kernel .
Part 4. Short scan with Parker's weights
The ray and the ray are the same line, because and .
Lemma 4 (weights). Let be a function with a Lipschitz derivative and on the support of . Then .
Proof. Split into and and substitute in the second part. Since is even, . The two parts add to , which is by (1).
Lemma 5 (Parker's weights add to 1). Let and . Define for by for , by 1 for , and by for , and put for the other modulo . Then the weights of the two copies of each line add to 1.
Proof. There are three cases. If , the copy lies in , which is the last region for the fan angle . Its weight is , and the sum is 1. If , then and , so the other copy is outside the scan or on its edge, where the weight is 0. If , the copy lies in , the first region for , and its argument and the argument of add to . Again the sum is 1.
The weight is continuous with a continuous derivative in . The derivative of at and is 0, which joins the pieces. If the support of lies in with , only fan angles with carry data, and there the weight has a Lipschitz derivative in .
Theorem 2 (short scan). Under these conditions,
Proof. Take as the Parker weight, written in parallel coordinates through . Lemma 5 gives the hypothesis of Lemma 4. Then repeat Part 3 with in place of and without the factor of (1). The weight is 0 for .
This is the factor 2 that the function _angles returns for the short scan.
Part 5. What the discrete algorithm approximates
Line L2 replaces by the ramp band-limited to and sampled at , which gives the values : at , 0 at even , and at odd . The values come from Lemma 2 of the filtered back-projection proof. Line L5 replaces the integral over by the sum with step , line L8 reads the filtered projection at by linear interpolation, and line L9 replaces the integral over by the rectangle rule with step . For a full scan the integrand is periodic in , 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 makes the band limit in only approximately a band limit in , 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 .
- Lines L3 to L5 take for each source with the direct sum, or with an FFT of length at least , so or in total.
- Lines L6 to L8 take for each source and pixel, so .
The total is time with an FFT and with the direct sum, which the code uses. The extra space is for the filtered projections and the image. This is the same order as parallel-beam FBP. The weight and the angle 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 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 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 each, which is the inside .
- Not local. As in parallel FBP, the kernel decays like 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 weight, but the interpolation smooths the data.
- Flat detector. The formula with uses the plain ramp and the weight . This is the 2D case of the Feldkamp-Davis-Kress algorithm.
- Short scan. Parker's weights reduce the scan to 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 is not the parallel ramp. Using in place of drops the factor and the . The scale is then wrong by a factor 2, and the shape of the kernel is wrong away from its center.
- Missing . 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 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 and on the start angle. Check the sum rule in the geometry of the code, as the test does.
- Center of rotation. The central ray must hit the detector at the position . 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.
# 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 and the kernel 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
- 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
- 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)
- 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.
| Ladder | Level | What the next level needs |
|---|---|---|
| Human proof | H1 sketch |
|
| Lean | L0 no Lean part |
|
| Code (python) | I0 not checked yet |
|
| Visual | V0 none |
|
| Writing | W2 basic |
|
Tag 2Y6GKS Edit this page History Report an error Markdown