Algorithmadvanced
Lambda tomography
Also called local tomography.
Reconstruct Lambda f, the square root of minus the Laplacian of f, from local data. It is not f, but it has the same edges, and each value needs only the rays near the point.
- Solves
- Interior tomography
- Time
- O(a d + a n^2) worst
- Space
- O(a d + n^2) extra
- Where
- a = the number of projection angles; 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
- A. Faridani, E. L. Ritman, K. T. Smith, 1992
Lambda tomography reconstructs, from parallel-beam CT data, the image in place of the attenuation . The algorithm is filtered back-projection with the ramp filter replaced by minus the second derivative: . A second derivative is local, so the value at a point needs only the rays that pass near that point. This makes the method work on truncated projections, where the interior problem has no unique solution for . The output is not . It has the same edges as , at the same places, but its values are different: has no mean value and is unbounded at a jump. With angles, bins and an image it takes time.
In plain words
Ordinary CT needs every ray through the whole object. The filter of ordinary CT has long tails, so a pixel is affected by rays that pass far from it. If the detector is too small and some rays are missing, every pixel gets some error.
Lambda tomography uses a short filter: at each detector cell, it compares the reading with its two neighbors. A pixel then depends only on the rays that pass close to it. If the region of interest is fully covered by the measured rays, the missing rays do not matter.
The price is that the picture is not the density. It is a sharpened version of the density, in which a constant area is close to flat but each boundary shows as a strong bright and dark line. For finding edges, cracks and the shape of a structure, this is often enough.
The problem
The data is a parallel sinogram for and . Row samples at , and bin has its center at . Here is the Radon transform, with and . The back-projection is , the back-projection operator. Bins outside the measured range count as 0. The output is an image on , with pixel centered at and .
With the Fourier transform in ordinary frequency, multiplies by , and multiplies it by . The algorithm evaluates
Some texts write without the constant. The constant makes the output equal to in this convention. The term is not local. It adds a smooth image that brings back some of the contrast between regions.
The algorithm
LAMBDA(P, τ, n, μ) ▷ P[k][j]: angle θ_k = kπ/a, bin center s_j = (j - (d-1)/2) τ- 1
a, d ← the number of rows and of columns of P - 2
q_k[j] ← -(P[k][j+1] - 2 P[k][j] + P[k][j-1])/τ² + μ P[k][j] for each k and j ▷ P = 0 outside - 3
for each pixel (i, j) with center (x_j, y_i) do - 4
f[i][j] ← Σ_k LININTERP(q_k, (x_j cos θ_k + y_i sin θ_k)/τ + (d-1)/2) - 5
return f/(2a)
Line L2 is the central second difference, which approximates , plus the optional term. Line L4 is the discrete back-projection, with linear interpolation and 0 outside the detector. Line L5 applies the weight . With , the value at a pixel uses only the bins whose centers lie within of in each row.
Example
Take the disk of radius with density 1. Its projection is at every angle. With bins and :
| quantity | values at |
|---|---|
| projection | 0, 0, 0.8660, 1, 0.8660, 0, 0 |
| filtered | 0, -13.8564, 11.7128, 4.2872, 11.7128, -13.8564, 0 |
The center value is . With angles the value at the origin is . The filtered profile is large and positive just inside the edge and negative just outside it, which is how the edge shows up.
The exact of this disk follows from the formula. The projection has , so for , with ,
where is the complete elliptic integral of the second kind. At the center and , so the coarse example above is off by 7 percent. The value grows like near the edge.
A finer grid, measured with the code: angles, bins, . These are measurements of this setup.
| point | code | exact |
|---|---|---|
| 2.0038 | 2 | |
| 2.5143 | 2.4912 | |
| 4.7938 | 4.5142 | |
| 8.1860 | 7.8518 | |
| , outside the disk | -2.6084 | negative |
For the Gaussian the exact value at the origin is . The code gives there, and its largest error over the grid against the exact formula is .
Correctness
The proof in proofs/correctness.md has four parts. First, by the Fourier slice theorem and polar coordinates, back-projecting a projection filtered by the multiplier gives the image filtered by . With , the multiplier of , this gives , and with it gives . Second, the formula needs only on the lines through the point, so it is local. Third, the second difference has the error , the linear interpolation has the error , and the sum over angles is the trapezoidal rule for a periodic function. The discrete value at a point uses only the bins within of the lines through it. Fourth, is an elliptic pseudodifferential operator of order 1, so and have the same singular support. This is the theorem behind the method: the edges are in the right places.
Proof: Correctness of lambda tomographyfull
We use the conventions of the page. , the Radon transform is , the back-projection is , and the Fourier transform is . The operator has the multiplier , so , and has the multiplier .
The proof has four parts. Part 1 proves the formula that the algorithm discretizes. Part 2 proves that it is local. Part 3 says what the algorithm computes in the discrete case and why the computed value at a point uses only the data near the lines through it. Part 4 proves that has the same singular support as , which is why the method shows the edges.
Part 1. The formula
Lemma 1 (filtered back-projection with a general filter). Let , and let be an even continuous function on with . Put , where is the 1D transform of . If , then
Proof. By the Fourier slice theorem, . So
The map from covers the plane once up to a null set, with . Since is even, , and the integral becomes the right side. It converges absolutely by the hypothesis, so Fubini applies.
Theorem 1. For ,
Proof. The function decays faster than any power. For the first formula take , which is the multiplier of . Lemma 1 gives . For the second take . The integral converges in 2D, because is integrable near 0 in the plane. Lemma 1 gives .
Compare with filtered back-projection, which uses and gives itself. Lambda tomography uses , which is times , so its output is filtered by .
Part 2. Locality
Corollary 1. depends only on the values of on any open set of lines that contains all lines through .
Proof. By Theorem 1, . For each , the second derivative at depends only on in a neighborhood of , and the line passes through .
So if the data is known only for the lines that meet a disk , then is known on the open disk . In particular, truncated projections give exactly inside the region of interest, while itself is not determined there (interior tomography). The operator is not local: uses on the lines through , but these lines leave the region of interest.
Part 3. The discrete algorithm
Line L2 replaces by the central second difference
with . For Taylor expansion gives for some , so the error is at most . Line L4 reads at by linear interpolation, with the error at most for a smooth , and line L5 replaces by . The integrand has the period in , so this is the trapezoidal rule for a periodic function, which converges faster than any power of for smooth . With the output is therefore for every and smooth . With it is up to the same errors, by the second formula of Theorem 1.
The discrete method is local in the same way as the continuous formula. The value at uses, for each , two interpolation nodes and around the fractional index , and and use . All of these bins have centers within of . So with the output at does not change when the data changes only at bins with in row . The test checks this with random changes outside , which is a smaller set since .
Part 4. Edges
Theorem 2. For a distribution with compact support, and have the same singular support, that is, is smooth near a point if and only if is.
Proof sketch with the standard tools. is a classical pseudodifferential operator of order 1 with the principal symbol , after a smooth cutoff of the symbol near , which changes only by a smooth function. Every pseudodifferential operator is pseudolocal, so the singular support of lies in that of . The symbol does not vanish for , so is elliptic and has a parametrix of order with smooth. Pseudolocality of gives the other inclusion.
This is the theorem that justifies the method: the jumps of show up in at the same places. The values are not the same. multiplies the Fourier transform by , so it removes the mean and changes the size of each feature. At a jump of a piecewise smooth , is not bounded: for the disk of radius it grows like near the edge from inside. The page computes this case in closed form.
Complexity
In the real-RAM model, line L2 takes per row, in total. Lines L3 and L4 take per angle and pixel, in total. The total is time and space. The filter is cheaper than the ramp filter of FBP, which takes per row with an FFT, but the back-projection dominates both. To reconstruct only a region of interest with pixels, the cost is , and the data needs to cover only the lines that meet the region.
Properties
- Local. With the value at a point depends only on the data on lines within a small distance of the point. Truncated projections give exact values (up to discretization) inside the region that the measured lines cover.
- Not the density. has the Fourier transform , which is 0 at . So for an integrable , and a large constant region has a value near 0 far from its edges.
- Same edges. is smooth exactly where is smooth. At a jump, is unbounded, with opposite signs on the two sides, as the disk example shows.
- Linear. The output is a linear function of the data.
- Noise. The filter of line L2 with the factor has the response . At the Nyquist frequency this is , against for the ramp of FBP, so it amplifies the noise at high frequency by the factor more. Practical codes smooth the data first.
Variants and improvements
- Lambda plus a smooth part. adds back some low-frequency contrast. The second term is not local, so with truncated data it is only approximate. The code supports it with the parameter .
- Smoothed kernels. Replace by a smooth kernel with the same behavior at high frequency, such as the second derivative of a Gaussian. The result is a smoothed , and the locality radius grows to the width of the kernel.
- Fan-beam and cone-beam data. The same idea works for divergent beams with a change of variables, as in fan-beam filtered back-projection.
- Exact interior reconstruction. If extra knowledge is available, for example the values of on a small subregion, the interior problem has a unique solution and other methods recover itself (interior tomography).
When to use it
Use lambda tomography when the detector does not cover the whole object, or when only a small region is of interest, and the goal is to find edges, boundaries or small features, not to measure densities. Examples are a region of interest scan of a large sample in micro CT, or the search for cracks in a part. Do not use it when the attenuation values themselves matter. In that case use full data and filtered back-projection, or interior tomography with extra knowledge.
Pitfalls
- Reading the values as densities. is not . A region of constant density shows as nearly 0 inside, with strong lines at its boundary.
- The missing constant. The formula without the factor gives . The scale does not matter for edge detection, but it matters when the result is combined with other images.
- Noise. The second difference has a large gain at high frequency. Without smoothing the image is dominated by noise.
- Wrong edges for the variant. The term is not local, so with truncated data it adds an error that is smooth but not small. Choose by experiment and do not read the result as .
- Data that is not zero at the detector ends. The code treats the bins outside the detector as 0. At a truncated detector the second difference at the last bin then sees a jump and gives a large value. These values only affect pixels whose lines pass within of the detector end, so keep the region of interest at least that far inside.
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/lambda-tomography/. The authors are listed in prov/8VWFH5.jsonl.
"""Lambda tomography: the local reconstruction Lambda f = (1 / (2 pi)) R^# (-d^2/ds^2) R f.
Conventions:
- omega(t) = (cos t, sin t). The sinogram P[k][j] samples the Radon transform
R f(theta_k, s_j) with theta_k = k pi / a and s_j = (j - (d - 1) / 2) tau.
- R^# g(x) = integral_0^pi g(theta, x . omega(theta)) dtheta, approximated by
(pi / a) sum_k.
- Lambda = (-Laplacian)^(1/2), with the Fourier multiplier 2 pi |xi| in
ordinary frequency. Lambda^(-1) f = (1 / (2 pi)) R^# R f.
- The output is an n x n image on [-1, 1]^2, pixel (i, j) centered at
x_j = -1 + (2 j + 1) / n and y_i = 1 - (2 i + 1) / n.
- A sample outside the detector counts as 0. Only the samples within one bin
of x . omega(theta_k) enter the value at x (with mu = 0).
"""
import math
def lambda_filter(p, tau, mu=0.0):
"""q_j = -(p_(j+1) - 2 p_j + p_(j-1)) / tau^2 + mu p_j, with p = 0 outside the detector."""
d = len(p)
out = []
for j in range(d):
left = p[j - 1] if j > 0 else 0.0
right = p[j + 1] if j + 1 < d else 0.0
out.append(-(right - 2.0 * p[j] + left) / (tau * tau) + mu * p[j])
return out
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 lambda_tomography(sino, tau, n, mu=0.0):
"""Lambda f + mu Lambda^(-1) f on an n x n grid from a parallel sinogram on [0, pi)."""
a, d = len(sino), len(sino[0]) # @line L1
qs = [lambda_filter(p, tau, mu) for p in sino] # @line L2
xs = [-1.0 + (2 * j + 1) / n for j in range(n)]
ys = [1.0 - (2 * i + 1) / n for i in range(n)]
c0 = (d - 1) / 2.0
img = [[0.0] * n for _ in range(n)]
for k, q in enumerate(qs):
c, s = math.cos(k * math.pi / a), math.sin(k * math.pi / a)
for i, y in enumerate(ys): # @line L3
row = img[i]
for j, x in enumerate(xs):
row[j] += lin_interp(q, (x * c + y * s) / tau + c0) # @line L4
w = 1.0 / (2.0 * a) # (1 / (2 pi)) * (pi / a)
return [[w * v for v in row] for row in img] # @line L5
def lambda_at(sino, tau, x, y, mu=0.0):
"""The value of lambda_tomography at one point (x, y)."""
a, d = len(sino), len(sino[0])
c0 = (d - 1) / 2.0
total = 0.0
for k, p in enumerate(sino):
q = lambda_filter(p, tau, mu)
theta = k * math.pi / a
total += lin_interp(q, (x * math.cos(theta) + y * math.sin(theta)) / tau + c0)
return total / (2.0 * a)
test_lambda_tomography.py 104 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/lambda-tomography/. The authors are listed in prov/8VWFH5.jsonl.
import math
import random
from lambda_tomography import lambda_at, lambda_filter, lambda_tomography, lin_interp
A, D, N = 32, 65, 16
TAU = 2.0 * math.sqrt(2.0) / D
XS = [-1.0 + (2 * j + 1) / N for j in range(N)]
YS = [1.0 - (2 * i + 1) / N for i in range(N)]
def sinogram(fun, a=A, d=D, tau=TAU):
return [[fun(k * math.pi / a, (j - (d - 1) / 2.0) * tau) for j in range(d)] for k in range(a)]
def gauss(theta, s):
"""R f for f(x) = exp(-4 pi |x|^2)."""
return 0.5 * math.exp(-4.0 * math.pi * s * s)
def disk(theta, s, radius=0.5):
return 2.0 * math.sqrt(radius * radius - s * s) if abs(s) < radius else 0.0
def lambda_gauss(x, y, m=400):
"""(1 / (2 pi)) integral_0^pi -p''(x . omega) dtheta for p(s) = exp(-4 pi s^2) / 2, by the midpoint rule."""
total = 0.0
for k in range(m):
th = (k + 0.5) * math.pi / m
s = x * math.cos(th) + y * math.sin(th)
total += 0.5 * (8.0 * math.pi - 64.0 * math.pi ** 2 * s * s) * math.exp(-4.0 * math.pi * s * s)
return total / (2.0 * m)
def test_filter_values() -> None:
q = lambda_filter([0.0, 1.0, 4.0, 1.0], 0.5, mu=2.0)
assert q == [-4.0 + 0.0, -(4.0 - 2.0) * 4.0 + 2.0, -(1.0 - 8.0 + 1.0) * 4.0 + 8.0, -(0.0 - 2.0 + 4.0) * 4.0 + 2.0]
assert lin_interp([1.0, 3.0], 0.25) == 1.5 and lin_interp([1.0, 3.0], -1.0) == 0.0
def test_gaussian_matches_sqrt_minus_laplacian() -> None:
sino = sinogram(gauss)
# Lambda f(0) = integral 2 pi |xi| (1/4) exp(-pi |xi|^2 / 4) d xi = 2 pi
assert abs(lambda_at(sino, TAU, 0.0, 0.0) - 2.0 * math.pi) < 0.15
img = lambda_tomography(sino, TAU, N)
for i in range(N):
for j in range(N):
assert abs(img[i][j] - lambda_gauss(XS[j], YS[i])) < 0.2
def test_disk_values() -> None:
sino = sinogram(disk)
# For the disk of radius R: Lambda f(0) = 1 / R, and it grows toward the edge and is negative outside.
assert abs(lambda_at(sino, TAU, 0.0, 0.0) - 2.0) < 0.05
want = 2.0 * sum((1.0 - 0.25 * math.cos((k + 0.5) * math.pi / 2000) ** 2) ** -1.5 for k in range(2000)) / 2000
assert abs(lambda_at(sino, TAU, 0.25, 0.0) - want) < 0.1
assert lambda_at(sino, TAU, 0.45, 0.0) > 4.0
assert lambda_at(sino, TAU, 0.6, 0.0) < 0.0
def test_local_data_suffices() -> None:
# Change the data far from the point: the value at the point does not change.
rng = random.Random(7)
sino = sinogram(gauss)
x, y = 0.2, -0.1
radius = math.hypot(x, y) + 2.0 * TAU
changed = [
[v if abs((j - (D - 1) / 2.0) * TAU) <= radius else v + rng.uniform(-5, 5) for j, v in enumerate(row)]
for row in sino
]
assert lambda_at(changed, TAU, x, y) == lambda_at(sino, TAU, x, y)
# truncated data: zero outside |s| < 0.4
cut = [[v if abs((j - (D - 1) / 2.0) * TAU) < 0.4 else 0.0 for j, v in enumerate(row)] for row in sino]
assert abs(lambda_at(cut, TAU, 0.05, 0.05) - lambda_at(sino, TAU, 0.05, 0.05)) < 1e-12
def test_mu_term_adds_the_smooth_part() -> None:
sino = sinogram(gauss)
mu = 3.0
with_mu = lambda_at(sino, TAU, 0.0, 0.0, mu)
without = lambda_at(sino, TAU, 0.0, 0.0)
# Lambda^(-1) f(0) = (1 / (2 pi)) integral_0^pi R f(theta, 0) dtheta = 1/4 for this Gaussian
assert abs((with_mu - without) / mu - 0.25) < 1e-12
# in general the mu term is mu / (2 a) times the plain back-projection of the data
x, y = 0.3, 0.1
plain = 0.0
for k, row in enumerate(sino):
th = k * math.pi / A
plain += lin_interp(row, (x * math.cos(th) + y * math.sin(th)) / TAU + (D - 1) / 2.0)
diff = lambda_at(sino, TAU, x, y, mu) - lambda_at(sino, TAU, x, y)
assert abs(diff - mu * plain / (2.0 * A)) < 1e-12
def test_point_and_grid_agree() -> None:
sino = sinogram(disk, a=8, d=33, tau=0.05)
img = lambda_tomography(sino, 0.05, 4)
xs = [-1.0 + (2 * j + 1) / 4 for j in range(4)]
ys = [1.0 - (2 * i + 1) / 4 for i in range(4)]
for i in range(4):
for j in range(4):
assert abs(img[i][j] - lambda_at(sino, 0.05, xs[j], ys[i])) < 1e-12
History
Faridani, Ritman and Smith published their paper Local Tomography in 1992. They based the method on the operator and on the fact that has the same singularities as . Faridani, Finch, Ritman and Smith continued the work in Local Tomography II in 1997. The formula itself follows from the Fourier slice theorem in the same way as filtered back-projection.
References
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 8VWFH5 Edit this page History Report an error Markdown