Exercise: reconstruction as a linear system
Before this unit: Filtered back-projection and sampling (previous unit); Day 1: Images, filters and frequencies.
See also: Day 4: Image formation; Day 5: Deconvolution; Day 21: Hough transform; Day 28: Ising model and Markov random fields.
Goal
By the end of this exercise you should be able to:
- write the system A\mathbf x = \mathbf b of a tiny scan, find its rank and null space, and say what extra rays would fix,
- recognise A^\top as back-projection,
- run ART (Kaczmarz) and SIRT steps by hand, and draw ART for two pixels,
- explain semi-convergence and what priors (non-negativity, total variation) add.
Do the pen-and-paper part first, then the two demos. Questions marked (math) are for those who want the derivations; the concept questions do not depend on them.
Background
| Idea | What it means |
|---|---|
| A\mathbf x = \mathbf b | \mathbf x: pixel values; \mathbf b: ray sums; row i of A: the weights of ray i (here 1 for every pixel on the ray) |
| Null space | images \mathbf v with A\mathbf v = 0: invisible to the scan |
| A^\top\mathbf y | back-projection: each y_i added to the pixels of ray i |
| ART (Kaczmarz) | for one ray: error = data − current sum; add error / (number of pixels on the ray) to each of its pixels, times \omega |
| SIRT | errors of all rays, each divided by its number of pixels, back-projected and averaged at each pixel (divided by the number of rays through it), times \omega |
| Pixels of a 2 \times 2 image | (a, b; c, d): top row a, b, bottom row c, d |
By hand
B1. The 2 \times 2 image \begin{bmatrix}1&2\\3&4\end{bmatrix} is measured by its row sums (top, bottom) and column sums (left, right). (a) Write the 4 \times 4 matrix A and the data \mathbf b. (b) Check that \begin{bmatrix}2&1\\2&5\end{bmatrix} gives the same data. Compute the difference of the two images and check that A maps it to 0. (c) What is the rank of A? How many different real-valued images fit the data?
B2. Add the diagonal ray a + d (and, if you like, the other diagonal b + c). (a) What do the two images of B1 give for it? (b) Is the null-space image of B1 still invisible? What is the rank now?
B3. ART by hand: start from \mathbf x = 0 and use the rays in the order row 1, row 2, column 1, column 2, with \omega = 1. (a) Write \mathbf x after each of the four steps. (b) Which of the two images of B1 do you get? Compute the squared norm \|\mathbf x\|^2 of both. Why does ART return this one?
B4. SIRT by hand, from \mathbf x = 0, \omega = 1. (a) Compute one SIRT step. (b) Compute A^\top\mathbf b (back-project the four data values). Compare with (a). (c) Is the result of (a) a good image? What is right about it, what is wrong?
B5. Two pixels (x_1, x_2), \omega = 1, start at (0, 0). (a) Lines x_1 + x_2 = 5 and x_1 - x_2 = -1. Do one ART sweep (first line, then second). Sketch. (b) Lines x_1 + x_2 = 5 and x_1 + 1.2x_2 = 5.6. Do one sweep. Where is the solution? Why is ART slow here? What kind of rays give nearly parallel lines?
B6. Three inconsistent measurements of two pixels: x_2 = 4, x_1 = 2, x_1 + x_2 = 5.5. (a) Do they have a common solution? (b) Start ART at (1.75, 3.75) and do one sweep in the given order. What do you notice? (c) What does a relaxation \omega < 1 change?
B7. A 3 \times 3 image measured by its row and column sums (6 rays). (a) How many unknowns, how many equations? The rank is 5: what is the dimension of the null space? (b) Check that the image \begin{bmatrix}1&0&-1\\0&0&0\\-1&0&1\end{bmatrix} is in the null space. Find another one. (c) Adding the five diagonals in one direction raises the rank to 8, both diagonal directions to 9. What does that mean for the reconstruction?
B8. Sparsity. A 256 \times 256 image, 400 angles, 256 detector bins. (a) How many rows and columns does A have, and how many entries? (b) A ray passes about 256 rows of the image and touches about 2 pixels per row. What fraction of a row of A is non-zero?
B9. Total variation in 1D: \mathrm{TV} = \sum|x_{k+1} - x_k|. (a) Compute the TV of (0, 0, 1, 1), (0, 1, 0, 1) and (0, \tfrac13, \tfrac23, 1). (b) Which of these does a TV prior prefer, and which one does it punish? What does that mean for noise, and for a smooth ramp?
B1. (a) With \mathbf x = (a, b, c, d): A = \begin{bmatrix}1&1&0&0\\0&0&1&1\\1&0&1&0\\0&1&0&1\end{bmatrix}, \mathbf b = (3, 7, 4, 6). (b) (2 + 1, 2 + 5, 2 + 2, 1 + 5) = (3, 7, 4, 6). The difference (1, -1, -1, 1): row sums 1 - 1 = 0, -1 + 1 = 0, column sums 1 - 1 = 0, -1 + 1 = 0. (c) Rank 3 (the four sums are dependent: row sums and column sums both add up to the total). The null space is one-dimensional, so infinitely many real images fit: \begin{bmatrix}1&2\\3&4\end{bmatrix} + t\begin{bmatrix}1&-1\\-1&1\end{bmatrix} for every t.
B2. (a) a + d = 5 for the first image, 2 + 5 = 7 for the second: different. (b + c = 5 and 3.) (b) The null image gives a + d = 1 + 1 = 2 \ne 0: the diagonal ray sees it. The rank becomes 4, and the data determine the image.
B3. (a) Row 1: error 3 - 0 = 3, add 1.5 to a, b: (1.5, 1.5, 0, 0). Row 2: error 7: (1.5, 1.5, 3.5, 3.5). Column 1: a + c = 5, error -1: (1, 1.5, 3, 3.5). Column 2: b + d = 5, error +1: (1, 2, 3, 4). (b) \begin{bmatrix}1&2\\3&4\end{bmatrix}, with \|\mathbf x\|^2 = 1 + 4 + 9 + 16 = 30, against 4 + 1 + 4 + 25 = 34 for the other. ART only ever adds multiples of rows of A to a zero start, so it never adds any part of the null-space image: it returns the solution with no null-space component, the smallest one. The data cannot tell which is true; ART’s choice is a convention, not knowledge.
B4. (a) Errors (3, 7, 4, 6), each divided by 2 pixels: (1.5, 3.5, 2, 3). Each pixel lies on one row and one column ray: average of the two: a = (1.5 + 2)/2 = 1.75, b = (1.5 + 3)/2 = 2.25, c = (3.5 + 2)/2 = 2.75, d = (3.5 + 3)/2 = 3.25. (b) A^\top\mathbf b = (3 + 4, 3 + 6, 7 + 4, 7 + 6) = (7, 9, 11, 13), exactly 4 times (a): the first SIRT step is a scaled back-projection. (c) The ordering is right (a < b < c < d), and the mean is right (2.5), but the values are pulled towards the mean: the differences are halved. Blurred, like plain back-projection; further iterations sharpen it.
B5. (a) First line: error 5 - 0 = 5, \|\mathbf a\|^2 = 2: (2.5, 2.5). Second: -1 - 0 = -1, step -\tfrac12(1, -1): (2, 3). Solved in one sweep: the lines are perpendicular. (b) First line: (2.5, 2.5). Second: error 5.6 - 5.5 = 0.1, \|\mathbf a\|^2 = 2.44, step 0.041\,(1, 1.2): (2.541, 2.549). The solution is (2, 3). The lines are only 5° apart, so each projection moves along a direction almost parallel to the other line and gains very little: after 30 sweeps ART is still 0.55 away. Nearly parallel lines come from rays that cover almost the same pixels with almost the same weights, e.g. neighbouring angles.
B6. (a) No: x_1 = 2, x_2 = 4 gives x_1 + x_2 = 6 \ne 5.5. (b) x_2 = 4: (1.75, 4); x_1 = 2: (2, 4); x_1 + x_2 = 5.5: error -0.5, (1.75, 3.75). Back at the start: ART circles forever around a small triangle and never settles. (c) With \omega < 1 each step goes only part of the way to the line; the cycle shrinks, and as \omega \to 0 it shrinks onto a point close to the least-squares solution (1.83, 3.83).
B7. (a) 9 unknowns, 6 equations, rank 5: null space of dimension 9 - 5 = 4. (b) Its rows sum to 0, 0, 0 and its columns to 0, 0, 0. Another: \begin{bmatrix}1&-1&0\\-1&1&0\\0&0&0\end{bmatrix} (any 2 \times 2 checkerboard placed in two rows and two columns). (c) Rank 8: a one-dimensional null space remains (one invisible pattern); rank 9: the data determine the image completely (with exact data).
B8. (a) 400 \cdot 256 = 102\,400 rows, 65\,536 columns, 6.7 \cdot 10^9 entries. (b) About 512 non-zeros of 65 536: 0.8 %. Stored as a full matrix of 4-byte numbers it would take 27 GB; as a sparse matrix about 50 million entries; in practice not stored at all.
B9. (a) 1, 3, 1. (b) TV punishes oscillations (0, 1, 0, 1: 3), so noise is expensive and gets removed. A step and a ramp of the same height cost the same (1): TV does not prefer smooth ramps, and in the presence of noise it often turns a ramp into a staircase of flat steps.
Math questions
B10. (math) Show that the Kaczmarz step \mathbf x' = \mathbf x + \frac{b_i - \mathbf a_i^\top\mathbf x}{\|\mathbf a_i\|^2}\mathbf a_i is the orthogonal projection of \mathbf x onto the hyperplane \mathbf a_i^\top\mathbf x = b_i: check that \mathbf x' lies on it and that \mathbf x' - \mathbf x is perpendicular to it. Check that it reproduces B3 (the rows have \|\mathbf a_i\|^2 = 2).
B11. (math) Show that ART started at \mathbf x_0 = 0 stays in the row space of A. Use this to show that, if it converges to a solution of A\mathbf x = \mathbf b, that solution has the smallest norm among all solutions.
B12. (math) Show that SIRT with W_r = W_c = I is gradient descent on \tfrac12\|A\mathbf x - \mathbf b\|^2 with step \omega, and that its fixed points satisfy the normal equations A^\top A\mathbf x = A^\top\mathbf b. For the 2 \times 2 example compute A^\top A and check that (1, 2, 3, 4) satisfies them.
B10. \mathbf a_i^\top\mathbf x' = \mathbf a_i^\top\mathbf x + (b_i - \mathbf a_i^\top\mathbf x) = b_i: on the hyperplane. \mathbf x' - \mathbf x is a multiple of \mathbf a_i, the normal of the hyperplane: perpendicular to it. So \mathbf x' is the closest point of the hyperplane. For a row with two ones, \mathbf a_i/\|\mathbf a_i\|^2 adds half the error to each of the two pixels: exactly the “spread evenly” of B3.
B11. Each step adds a multiple of some \mathbf a_i, so \mathbf x_k \in \operatorname{span}\{\mathbf a_i\} = the row space, which is closed, so the limit \mathbf x^* is in it too. Any solution is \mathbf x^* + \mathbf v with \mathbf v in the null space, which is orthogonal to the row space. So \|\mathbf x^* + \mathbf v\|^2 = \|\mathbf x^*\|^2 + \|\mathbf v\|^2 \ge \|\mathbf x^*\|^2.
B12. \nabla\tfrac12\|A\mathbf x - \mathbf b\|^2 = A^\top(A\mathbf x - \mathbf b), so \mathbf x \leftarrow \mathbf x + \omega A^\top(\mathbf b - A\mathbf x) is a gradient step. A fixed point has A^\top(\mathbf b - A\mathbf x) = 0. For the example A^\top A = \begin{bmatrix}2&1&1&0\\1&2&0&1\\1&0&2&1\\0&1&1&2\end{bmatrix}; A^\top A(1, 2, 3, 4) = (2 + 2 + 3,\ 1 + 4 + 4,\ 1 + 6 + 4,\ 2 + 3 + 8) = (7, 9, 11, 13) = A^\top\mathbf b. (So does (2, 1, 2, 5): the normal equations inherit the null space.)
Explore: ART and SIRT by hand
Mode: image: the true image (click a pixel to add 1) with its rays, the current estimate (orange frame: the pixels of the next ray), and the table of A with the data, the current ray sums and the residuals. Choose the ray directions (0°: columns, 90°: rows, 45° and 135°: diagonals) and 2 \times 2 or 3 \times 3. Next ray makes one ART step, sweep one pass over all rays, SIRT step one SIRT update; + null image adds a null-space image to the truth. The readout gives the rank and a null-space image. Mode: 2 pixels: each measurement is a line in the (x_1, x_2) plane; drag the square handle to move a line, the round one to turn it. Orange: the ART path from (0, 0); star: the least-squares point; purple (optional): SIRT.
E1. Preset 2×2: two images, same data. Read the rank and the null image. Press + null image: what happens to the true image, and to the data column?
E2. Preset ART: one sweep. Check the estimate against B3. Now press + null image (the truth becomes the other image), x = 0 and sweep again. What do you get, and why?
E3. Preset add a diagonal ray. Read the rank. Press sweep a few times. Does ART now find the true image? Try a SIRT step from x = 0 and compare with B4.
E4. Preset 3×3: rows and columns (a cross). Read the rank and the null image, and compare with B7. Run a few sweeps: what does ART return? Add the 45° diagonals and then the 135° ones: how does the rank change?
E5. Switch to mode: 2 pixels, preset 2 pixels: ART zig-zags. How many sweeps does ART need? Turn one line so that the two are nearly parallel (or choose nearly parallel rays: slow): where is ART after the 4 sweeps shown?
E6. Preset noisy: ART circles. Where does the ART path end up? Choose noisy, ω = 0.3 settles and compare. Tick show SIRT path: where does SIRT go?
E1. Rank 3 of 4 pixels, null image (1, -1; -1, 1). + null image turns the truth (1, 2; 3, 4) into (2, 1; 2, 5); the data column stays (3, 7, 4, 6). The scanner cannot see the change.
E2. After the preset the estimate is (1, 2; 3, 4), all residuals 0, as in B3. With the truth (2, 1; 2, 5) and a new sweep from 0 the estimate is again (1, 2; 3, 4), and again all residuals are 0: ART fits the data perfectly with the wrong image. It returns the minimum-norm image because the data hold no information about the null-space direction.
E3. Rank 4. With the diagonal rays ART converges to the true (2, 1; 2, 5) (exactly after enough sweeps; the ↘ set has three rays: b alone, a + d, c alone). The SIRT step from 0 is smoother and does not fit the data yet: it averages over all 7 rays.
E4. Rank 5, null image (1, 0, -1; 0, 0, 0; -1, 0, 1), as in B7 (the null space has dimension 4). ART returns (0.11, 0.78, 0.11; 0.78, 1.44, 0.78; 0.11, 0.78, 0.11): the smallest image with the right row and column sums (1, 3, 1), a blurred cross, not the binary cross. With the 45° diagonals the rank is 8, with both diagonal directions 9.
E5. Perpendicular lines: one sweep, after which the path stays at (2, 3). Lines 15° apart (the preset): after 4 sweeps ART is at (0.21, 1.21), still 2.5 from the solution (2, 3); it needs dozens of sweeps (0.42 away after 30).
E6. With \omega = 1 the path ends in a cycle around a triangle between the three lines, through (1.73, 3.80), (3.02, 3.45) and (1.73, 2.37), never reaching the least-squares point (2.23, 3.09). With \omega = 0.3 the cycle shrinks to a small triangle about 0.15 from the star (after 10 sweeps at (2.14, 2.95)). SIRT moves smoothly towards the star: after the 4 iterations shown it is at (2.20, 2.94), after 10 at (2.23, 3.08), and it ends at the star (2.23, 3.09): averaging the corrections of all lines is a least-squares step.
Explore: iterative reconstruction
A 128 \times 128 phantom measured with a chosen number of angles, angular range and photons per ray. Methods: FBP (Hann) for comparison, ART (one iteration = one sweep over all rays) and SIRT, with relaxation \omega, optional non-negativity and a TV step of weight \lambda after each data step. Each preset runs a number of iterations; run continues, +1 iteration steps. Panels: reconstruction, error, and the plot of the RMSE against the truth (red), the relative data residual \|A\mathbf x - \mathbf b\|/\|\mathbf b\| (blue) and the FBP error (dashed), per iteration.
E7. Preset SIRT step 1 = back-projection. Describe the image and read the RMSE. Why does it look like plain back-projection?
E8. Preset SIRT converging (100 iterations, 60 angles, no noise). How do the RMSE and the residual develop? Compare with FBP.
E9. Preset noisy: stop early (3000 photons per ray, ART, \omega = 0.5). At which iteration is the RMSE lowest? What does the residual do meanwhile? Which of the two can you watch in a real scan?
E10. Preset 30 views: FBP streaks vs TV clean. Compare the RMSE with FBP. Set \lambda to off (non-negativity only), then also untick non-negative. What does each prior contribute?
E11. Preset ±60° wedge: iterate with priors. Compare with FBP. Look at the top and bottom of the skull: is the missing wedge filled in?
E12. Presets noisy + TV and TV too strong: cartoon. Compare RMSE and appearance. What is lost when \lambda is too large?
E7. A blurred phantom with a glow, RMSE 0.206: the first SIRT step from zero is the normalised back-projection W_cA^\top W_r\mathbf b (B4). The iterations then remove the blur.
E8. Both fall steadily: RMSE 0.206 after 1 iteration, 0.144 after 10, 0.078 after 50 and 0.057 after 100 (residual 0.31, 0.13, 0.04, 0.02). From iteration 56 on SIRT beats FBP (0.074 with these 60 angles). SIRT is slow but, without noise, keeps improving.
E9. The RMSE is lowest after 5 sweeps (0.053) and then creeps up (0.056 after 30), while the residual keeps falling (0.012 → 0.010): the later iterations fit the noise. In a real scan there is no truth, only the residual, which keeps telling you to continue: the stopping point must be chosen in another way (a fixed number, or a rule such as stopping when the residual reaches the noise level, as on the deconvolution day). FBP (Hann): 0.075.
E10. FBP: 0.081, with streaks. ART + non-negativity + TV: 0.020 after 30 sweeps. Without TV (non-negativity only): 0.028, with faint streaks and noise-like ripples. Without non-negativity as well (plain ART) the error is 0.079, about as bad as FBP: the background between the streaks goes negative (about 1500 pixels below −0.02). Non-negativity removes the negative half of every streak; TV removes the ripples and keeps the edges.
E11. FBP: 0.132, the phantom stretched vertically. Iterative with priors: 0.067. The top and bottom of the skull come back much better, though not perfectly: the priors (non-negativity, piecewise constant) fill part of the missing wedge with the most plausible values, which the data cannot contradict.
E12. Noisy + TV (\lambda = 0.01): 0.027, clean flat regions with sharp edges. \lambda = 0.05: 0.048: a cartoon, with the small ellipses merged or flattened and low-contrast details gone. Too much prior overrides the data: fine texture and small, faint structures are what TV removes first.
Code
Write the algorithms of this unit yourself, in Rust. Setup, and how to run and check your code: coding exercises: getting started. Your code goes in radon/src/algebraic_recon/exercise.rs. The matrix A is stored by rows: row i lists the pixels that ray i touches, with their weights. The matrix of a real scan (the projector of the first unit, as a sparse matrix) is given.
C1. forward(a, x) and back(a, y, n_pixels): the products A\mathbf x (for every ray, the weighted sum of its pixels) and A^\top\mathbf y (every ray adds its value, with the same weights, to its pixels). The checks are B1, B2(b) and B4(b), and \langle A\mathbf x, \mathbf y\rangle = \langle \mathbf x, A^\top\mathbf y\rangle.
C2. art_sweep(a, b, x, ω): one sweep of ART over all rays, changing \mathbf x in place:
for every ray i:
error = b[i] − (sum over the ray's pixels j of a_ij · x[j])
norm2 = sum over the ray's pixels j of a_ij²
for every pixel j of the ray:
x[j] = x[j] + ω · error / norm2 · a_ij
The checks are B3 step by step, B5(a) and (b), and the cycle of B6(b).
C3. sirt_step(a, b, x, ω): one SIRT step:
r = b − A x # all errors, with the x you start with
for every ray i: r[i] = r[i] / (sum of the weights of ray i)
c = Aᵀ r
for every pixel j: x[j] = x[j] + ω · c[j] / (sum of the weights of the rays through j)
The checks are B4(a), and that many steps fit the data.
Then cargo run -p radon -- algebraic-recon and open the pictures in out/algebraic-recon/. The program reconstructs a 96 \times 96 Shepp–Logan phantom: with SIRT from 60 angles (after 1 and after 100 steps), with ART (\omega = 0.5) from 60 angles of noisy data, printing the error against the truth, the relative data residual \|A\mathbf x - \mathbf b\|/\|\mathbf b\| and the relative size of the noise, and with ART from only 20 angles, without and with non-negativity (negative pixels set to 0 after every sweep).
C4. Compare sirt-step1.png with sirt-100.png. What is the first SIRT step, and why does it look like that? (B4.)
C5. ART on noisy data: follow the error and the residual over the sweeps. When would you stop, and how could you know without the truth? Compare art-noisy-best.png with art-noisy-30.png.
C6. 20 angles: how much does non-negativity help, and where in the pictures?
The model solution is radon/src/algebraic_recon/solution.rs in the download.
C4. The first step from zero is a scaled back-projection (B4: A^\top\mathbf b divided by the weights): a blurred, glowing phantom, RMSE 0.193. After 100 steps the image is sharp, RMSE 0.083, and the residual is 0.024: the iterations remove the blur of back-projection step by step.
C5. RMSE after sweeps 1, 2, 3, 5, 10, 20, 30: 0.108, 0.086, 0.079, 0.0775, 0.080, 0.084, 0.088; the lowest, 0.0774, after sweep 4. The residual keeps falling: 0.160, 0.106, 0.074, 0.043, 0.022, 0.017, 0.016. After sweep 4 the iteration fits the noise: semi-convergence. Stop early. Without the truth: stop when the residual has fallen to the size of the noise in the data, which the program prints (0.037). That happens shortly after sweep 5, close to the best sweep; fitting the data any better means fitting the noise (a discrepancy rule, as for Richardson–Lucy on the deconvolution day). The 30-sweep image is grainier than the best one.
C6. Without the constraint the RMSE is 0.113, with it 0.062, almost half. Without it, streaks of positive and negative values run through the empty space around the head; setting the negative values to 0 removes most of them, and the inside of the head is cleaner too.
Where this leads
The same ideas (a linear forward model, least squares, early stopping, priors) run through the deconvolution day (regularisation) and through every modern reconstruction method. Low-dose clinical CT and electron tomography routinely use iterative reconstruction with priors; for emission tomography (PET, SPECT) the data term is the Poisson likelihood and the iteration is MLEM, which is Richardson–Lucy deconvolution with the projector as the blur.
The TV prior worked because the phantom has a sparse gradient. The sparse representations day makes sparsity the general prior: it solves such problems with thresholding iterations (ISTA) and asks how few measurements a sparse image needs (compressed sensing).