Exercise: projections and the sinogram
Before this 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:
- turn a transmitted fraction I/I_0 into a line integral of the attenuation, and back,
- compute projections of a few point masses at a few angles, by hand,
- read a sinogram: sinusoids, their amplitude and phase, crossings, the 180° mirror and the constant total,
- explain why two projections do not determine an image.
Do the pen-and-paper part first, then the demo. Questions marked (math) are for those who want the derivations; the concept questions do not depend on them.
Background
| Idea | What it means |
|---|---|
| Attenuation \mu | fraction of photons removed per cm (about 0.2 cm⁻¹ for soft tissue, more for bone) |
| Measurement | -\ln(I/I_0) = sum (integral) of \mu along the ray |
| Line (\theta, \rho) | all points with x\cos\theta + y\sin\theta = \rho; origin at the image centre, y up, \theta \in [0°, 180°) |
| Projection p_\theta(\rho) | the line integrals of all parallel lines at angle \theta; \theta = 0°: column sums, 90°: row sums |
| Sinogram | the projections side by side: \theta across, \rho up |
| A point (x, y) | lands at \rho = x\cos\theta + y\sin\theta = r\cos(\theta - \varphi) |
By hand
B1. Beer–Lambert with numbers. (a) A beam crosses 20 cm of water-like tissue (\mu = 0.2 cm⁻¹). Which fraction of the photons arrives? (b) The beam crosses 18 cm of tissue and 2 cm of bone (\mu = 0.5 cm⁻¹). What is -\ln(I/I_0), and I/I_0? Does it matter whether the bone comes first or last? (c) A detector reads I/I_0 = 0.05. What is the line integral of \mu along that ray? (d) Why does a CT scanner take the logarithm of the measured intensity before doing anything else?
B2. Three point masses: A = (2, 0) with mass 1, B = (0, 1) with mass 2, C = (-1, -1) with mass 1. (a) Draw the projections at 0°, 45°, 90° and 135° as bar plots on a \rho axis. (b) Check that every projection sums to the same number. Which number, and why?
B3. The sinogram of B2. (a) Give each point’s sinusoid as \rho = r\cos(\theta - \varphi): its amplitude r and the angle \varphi where it peaks. (b) Sketch the three curves for \theta from 0° to 180°. (c) At which angles do two curves cross, and at which \rho? What does a crossing mean for the measurement?
B4. Where in the sinogram is (a) a point at the image centre, (b) a point at (0, -3)? (c) A sinogram shows a sinusoid with amplitude 5 that peaks at \theta = 90°. Where is the point?
B5. You have measured p_{20°}(\rho). Without measuring again, what is p_{200°}(\rho)? Why does a parallel-beam scanner turn only half a turn?
B6. A uniform disc of radius 3 cm with \mu = 0.2 cm⁻¹, centred at the origin. (a) The ray at \rho crosses the disc along a chord of length 2\sqrt{9 - \rho^2}. Compute p_0(\rho) at \rho = 0, 1, 2, 2.5, 3 and sketch it. (b) Does the projection depend on \theta? What is the area under it? (c) The disc moves to (2, 0). Sketch p_0 and p_{90°} now. Describe its sinogram.
B7. A 3 \times 3 binary image has row sums (1, 2, 1) (top to bottom) and column sums (1, 2, 1) (left to right). (a) Find two different binary images with these sums. (b) Which small change of an image never changes its row and column sums? (c) Does a third projection at 45° always tell the images apart?
B1. (a) I/I_0 = e^{-0.2 \cdot 20} = e^{-4} = 0.018: under 2 %. (b) -\ln(I/I_0) = 18 \cdot 0.2 + 2 \cdot 0.5 = 3.6 + 1.0 = 4.6, so I/I_0 = e^{-4.6} = 0.010. The order does not matter: the fractions multiply, and multiplication does not care about order (after the logarithm: a sum). (c) -\ln 0.05 = 3.00. (d) Because then each reading is a sum of the unknowns along the ray (linear in \mu). Everything later (back-projection, filtering, linear systems) needs that linearity.
B2. (a) \rho = x\cos\theta + y\sin\theta:
| \theta | A (mass 1) | B (mass 2) | C (mass 1) |
|---|---|---|---|
| 0° | 2 | 0 | −1 |
| 45° | 1.41 | 0.71 | −1.41 |
| 90° | 0 | 1 | −1 |
| 135° | −1.41 | 0.71 | 0 |
Each projection is three bars of heights 1, 2, 1 at these positions. (b) Each sums to 1 + 2 + 1 = 4, the total mass: a projection only moves mass sideways onto the detector, every point lands somewhere exactly once.
B3. (a) A: r = 2, \varphi = 0° (peaks at 0°). B: r = 1, \varphi = 90°. C: r = \sqrt2 = 1.41, \varphi = -135°, i.e. the curve 1.41\cos(\theta + 135°) peaks at 225° and has its minimum, -1.41, at 45°. (c) Set the two \rho equal: A and B cross at \theta = 63.4° (\tan\theta = 2), \rho = 0.89; A and C at 108.4°, \rho = -0.63; B and C at 153.4°, \rho = 0.45. At a crossing both points lie on the same ray: that projection cannot tell them apart, it shows one bar with their summed mass.
B4. (a) r = 0: the flat line \rho = 0. The centre of rotation is the only point that never moves on the detector. (b) \rho = -3\sin\theta: zero at 0°, -3 at 90°. (c) r = 5, \varphi = 90°: the point (0, 5).
B5. p_{200°}(\rho) = p_{20°}(-\rho): the same rays, walked in the opposite direction, so the profile is mirrored. Turning from 180° to 360° measures nothing new.
B6. (a) p_0(\rho) = 0.4\sqrt{9 - \rho^2}: 1.20, 1.13, 0.89, 0.66, 0 at \rho = 0, 1, 2, 2.5, 3: a half-ellipse. (b) A disc looks the same from every direction: every projection is this half-ellipse. Area: \mu \cdot \pi R^2 = 0.2 \cdot 9\pi = 5.65, the total of the image. (c) p_0 is the same half-ellipse centred at \rho = 2; p_{90°} is centred at \rho = 0 (the disc’s y is 0). In the sinogram the band follows the sinusoid of the centre, \rho = 2\cos\theta.
B7. (a) For example \begin{bmatrix}1&0&0\\0&1&1\\0&1&0\end{bmatrix} and \begin{bmatrix}0&1&0\\1&0&1\\0&1&0\end{bmatrix}. Five binary images have exactly these sums. (b) Swapping a 2 \times 2 checkerboard: in two rows and two columns, change \begin{smallmatrix}1&0\\0&1\end{smallmatrix} into \begin{smallmatrix}0&1\\1&0\end{smallmatrix}. Every row and column keeps its sum. (c) No, not always: it removes some ambiguities but not all. With more angles fewer images agree with all the data. (The fourth unit counts this with the rank of a matrix.)
Math questions
B8. (math) Derive I = I_0\exp(-\int\mu\,ds) from dI/ds = -\mu(s) I. Which assumption about the photons does the equation make?
B9. (math) From \mathcal R f(\rho, \theta) = \int f(\rho\,\mathbf n_\theta + s\,\mathbf n^\perp_\theta)\,ds, prove (a) the shift rule f(\mathbf x - \mathbf t) \mapsto \mathcal R f(\rho - \mathbf t\cdot\mathbf n_\theta, \theta), (b) the symmetry \mathcal R f(-\rho, \theta + \pi) = \mathcal R f(\rho, \theta), (c) \int \mathcal R f\,d\rho = \iint f.
B10. (math) Show that the projection of a uniform disc (value \mu, radius R, centre 0) is 2\mu\sqrt{R^2 - \rho^2}, and check that its integral over \rho is \mu\pi R^2.
B11. (math) A point mass m at \mathbf x_0 is f = m\,\delta(\mathbf x - \mathbf x_0). Use the first form of the definition, \iint f\,\delta(\mathbf x\cdot\mathbf n_\theta - \rho)\,d\mathbf x, to show that its Radon transform is m\,\delta(\rho - \mathbf x_0\cdot\mathbf n_\theta), and write \mathbf x_0\cdot\mathbf n_\theta as r\cos(\theta - \varphi).
B8. Separate variables: dI/I = -\mu(s)\,ds, integrate from the source (I_0) to the detector: \ln I - \ln I_0 = -\int\mu\,ds. The equation says every photon has the same chance per unit length of being removed, independent of the others: one energy (otherwise \mu depends on the photon) and no scattered photons reaching the detector.
B9. (a) \int f(\rho\mathbf n + s\mathbf n^\perp - \mathbf t)\,ds; write \mathbf t = (\mathbf t\cdot\mathbf n)\mathbf n + (\mathbf t\cdot\mathbf n^\perp)\mathbf n^\perp and substitute s' = s - \mathbf t\cdot\mathbf n^\perp: \int f((\rho - \mathbf t\cdot\mathbf n)\mathbf n + s'\mathbf n^\perp)\,ds' = \mathcal R f(\rho - \mathbf t\cdot\mathbf n, \theta). (b) \mathbf n_{\theta + \pi} = -\mathbf n_\theta and \mathbf n^\perp_{\theta + \pi} = -\mathbf n^\perp_\theta: \mathcal R f(-\rho, \theta + \pi) = \int f(\rho\mathbf n - s\mathbf n^\perp)\,ds, the same integral with s \to -s. (c) (\rho, s) \mapsto \rho\mathbf n + s\mathbf n^\perp is a rotation (Jacobian 1), so \iint \mathcal R f\,d\rho = \iint f(\rho\mathbf n + s\mathbf n^\perp)\,ds\,d\rho = \iint f\,dx\,dy.
B10. By symmetry take \theta = 0: the line x = \rho meets the disc for |y| \le \sqrt{R^2 - \rho^2}, so \int f\,dy = 2\mu\sqrt{R^2 - \rho^2}. With \rho = R\sin u: \int_{-R}^R 2\mu\sqrt{R^2 - \rho^2}\,d\rho = 2\mu R^2\int_{-\pi/2}^{\pi/2}\cos^2 u\,du = \mu\pi R^2.
B11. \iint m\,\delta(\mathbf x - \mathbf x_0)\,\delta(\mathbf x\cdot\mathbf n_\theta - \rho)\,d\mathbf x = m\,\delta(\mathbf x_0\cdot\mathbf n_\theta - \rho) (sifting property). With \mathbf x_0 = r(\cos\varphi, \sin\varphi): \mathbf x_0\cdot\mathbf n_\theta = r(\cos\varphi\cos\theta + \sin\varphi\sin\theta) = r\cos(\theta - \varphi).
Explore
The demo shows a 128 \times 128 object on the left, with the rays of the current angle (yellow, the arrow shows the beam direction) and the detector (blue bar). The middle panel is the projection p_\theta(\rho); the right panel is the sinogram, filled in up to the current angle. Click in the object to drop a point mass (its mass is set by the slider); every point gets a coloured sinusoid on the sinogram, a dashed line in the projection and a dot on the detector. Drag moves the object shifts the whole object instead. 0°–360° extends the sinogram to a full turn. The readout gives the sum of the current projection, the total of the image, and each point’s current \rho. Distances are in pixels.
E1. Preset three points by hand (one unit of B2 = 16 pixels). Read \rho of the three points at 0°, 45° and 90° (use 0° and +45°) and compare with B2. What is the sum of each projection?
E2. Play the sinogram from 0°. At which angle do the red and green curves (A and B) cross? What do you see in the projection at that angle? Compare with B3.
E3. Preset the centre does not move. Which curve is flat? For the other two points, read their positions in the readout and predict the amplitude and the angle of the peak of their sinusoids. Check with the slider.
E4. Preset 180°–360° mirrors 0°–180°. Compare the sinogram column at 30° with the one at 210° (move the slider). What exactly is the relation? Which point has the largest amplitude, and why?
E5. Preset every column has the same sum. Read the sum of the projection at 0°, 30° and 45° and the total of the image. Are they equal? Why could they differ in the last digits on a pixel grid?
E6. Preset shift the object: drag the disc about 20 pixels to the right. How does the sinogram change? At which angles does the band move most, and at which not at all?
E7. Presets Shepp–Logan sinogram and a real image. In the Shepp–Logan sinogram, which feature of the phantom makes the two bright outer bands? Why are they brightest where they are tangent to the outline? Add a point mass of 8 inside the micrograph and find its curve.
E1. At 0°: A 32, B 0, C −16 pixels (2, 0, −1 units). At 45°: 22.6, 11.3, −22.6 (1.41, 0.71, −1.41). At 90°: 0, 16, −16 (0, 1, −1). Every projection sums to 4.0, the total.
E2. They cross at about 63°: there the two point masses lie on the same ray (A at \rho = 14.5, B at 14.3 pixels at 63°), and the projection shows one peak holding both masses, 1 + 2 = 3, instead of two separate bars.
E3. The point at the centre has the flat curve \rho = 0. The point at (40, 0) has amplitude 40 and peaks at 0°; the point at (-20, 30) has amplitude \sqrt{20^2 + 30^2} = 36.1 and peaks at \varphi = 123.7° (at 124° the readout gives \rho = 36.0).
E4. The column at 210° is the column at 30° upside down: p_{\theta + 180°}(\rho) = p_\theta(-\rho), the same rays walked the other way. The point mass at (36, 36) is farthest from the centre (r = 50.9), so its sinusoid has the largest amplitude.
E5. Total 1936.0; projection sums 1936.0 at 0°, 1936.8 at 30°, 1936.0 at 45°. Equal up to 0.04 %. At 0° and 90° the rays run exactly through pixel centres; at other angles the linear interpolation between pixels distributes each pixel’s value over neighbouring rays not quite evenly, so the sum is exact only on average.
E6. Every sinusoid moves by t_x\cos\theta + t_y\sin\theta: with \mathbf t = (20, 0) the band moves up by 20 at 0°, not at all at 90°, and down by 20 at 180°. The sinogram is bent, not slid.
E7. The bright outer bands come from the skull: the dense outer ring of the phantom. A ray that just grazes the ring runs a long way inside it (tangent), so its line integral is largest there. The point mass adds a thin sinusoid of its own on top of the micrograph’s sinogram: linearity.
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/radon/exercise.rs. The code uses the lecture’s coordinates: origin at the image centre, y up, angles counter-clockwise. Reading the image between pixels (bilinear interpolation, 0 outside) is given.
C1. rho(x, y, θ): where a point lands on the detector, \rho = x\cos\theta + y\sin\theta. The checks are B2 and the crossing of A and B in B3.
C2. projection(img, θ): the projection of an n \times n image, one detector bin per pixel width, \rho = k - c for bin k (c = the centre):
for every bin k:
ρ = k − c
sum = 0
for j in 0 .. n−1: # steps of 1 along the ray
s = j − c
(x, y) = ρ · (cos θ, sin θ) + s · (−sin θ, cos θ)
sum = sum + I(x, y) # between pixels: bilinear
p[k] = sum
The checks: at 0° the projection is the column sums (the image of B7), at 90° the row sums (bin 0 is the bottom row, as \rho = y grows upwards), and a disc gives the chord length of B6.
C3. sinogram(img, angles): the projections side by side, one column per angle. The checks: every column sums to the total of the image (B2(b)), and p_{\theta + 180°}(\rho) = p_\theta(-\rho) (B5).
Then cargo run -p radon -- radon and open the pictures in out/radon/ (sinograms with \theta across and \rho up). The program projects the three point masses of B2 (16 pixels per unit, each point a tiny spot holding its mass), the Shepp–Logan phantom, a disc in the centre and the same disc moved by (20, 12) pixels (over a full turn), and a piece of the micrograph.
C4. Read the printed projections of the three points at 0°, 45° and 90° and compare them with B2. Then find the crossings of the three curves in points-sinogram.png: which pair of points crosses where?
C5. Compare disc-centred-sinogram-360.png with disc-shifted-sinogram-360.png. Where is the band of the shifted disc highest, and how does the second half turn relate to the first?
C6. Count the cost: how many reads between pixels does a sinogram of a 128 \times 128 image at 180 angles need? And a 512 \times 512 image with the 800 angles of the angle rule?
The model solution is radon/src/radon/solution.rs in the download.
C4. At 0°: \rho = 2, 0, -1 with masses 1.00, 2.00, 1.00. At 45°: \rho = 1.41, 0.71, -1.41 with 1.00, 2.00, 1.01. At 90°: \rho = 0, 1, -1 with 1.00, 2.00, 1.00. Every projection sums to 4.00, as in B2. (The phantom’s projections sum to 2032.1 to 2033.7, its total is 2032.6: equal up to the interpolation.) In the sinogram the brightest curve is B (mass 2, amplitude 1 unit, peak at 90°), and the widest is A (amplitude 2, peak at 0°). A and B cross at 63.4° (\rho = 0.89), A and C at 108.4°, B and C at 153.4° (B3).
C5. The centred disc gives a straight band at \rho = 0 of constant width. The shifted disc’s band follows \rho = 20\cos\theta + 12\sin\theta: highest, \rho = 23.3, at \theta = 31°, lowest at 211°. From 180° to 360° the band repeats upside down: the same rays, walked the other way.
C6. Every bin of every angle takes n steps, each reading 4 pixels: 180 \cdot 128 \cdot 128 \cdot 4 = 1.2 \cdot 10^7 reads. For 512 \times 512 with 800 angles: 800 \cdot 512 \cdot 512 \cdot 4 = 8.4 \cdot 10^8, 70 times more. The work grows like n^3 when the number of angles grows with n.
Where this leads
The sinogram is all the scanner gives us. The next unit, back-projection, tries the most natural inversion, smearing every projection back over the image (back-projection), and finds out why it blurs; the Fourier slice theorem explains what is missing. Later units fix the blur with a filter (filtered back-projection) and then treat reconstruction as a linear system (reconstruction as a linear system).
The same (\rho, \theta) line parameters return on the Hough day: applied to a binary edge image, the Radon transform counts the edge pixels on every line, which is the Hough accumulator (Hough lines).