Cone-beam CT for Tomviz

Tomviz is an open source tool for reconstructing and visualising 3D tomography data. Today it reconstructs parallel-beam data: electron tomography and synchrotron CT. This project adds what lab and industrial X-ray CT scanners need, starting with cone-beam reconstruction, so that the same tool covers them too.

The work is being done in the open, and we would like to offer it to the Tomviz maintainers as a series of small pull requests. This page explains what is being added, why, and how far it has got. Code: the conebeam branch of our Tomviz fork.

Why

Most lab and industrial CT scanners have a point X-ray source, so the rays fan out in a cone from the source to a flat detector. Everything in Tomviz assumes parallel rays. Reconstructing cone-beam data as if it were parallel is only approximately right in the central slice and gets worse away from it.

Before reconstruction, raw X-ray projections also need flat-field and dark-field correction and a logarithm, which Tomviz does not have either. Without these steps, scanner data cannot be reconstructed in Tomviz at all.

What is being added

New operators, in the Tomography menu

Shared projectors that run on any GPU, or none

Underneath is a new package, tomviz.projectors: geometry for cone and parallel beams, a backprojector and a forward projector, written once as a WebGPU compute shader and once as plain NumPy. The shader runs through the optional wgpu package, which targets Vulkan, Metal and Direct3D 12, so it is not tied to one GPU vendor; so far it has been tested on Vulkan. Without a GPU it runs on a software driver (tested: Mesa lavapipe on Linux; WARP on Windows should work the same way but is untested), and only then falls back to NumPy.

That middle step matters more than expected. On 8 CPU threads and no GPU, the shader on lavapipe was 13 to 17 times faster than vectorised NumPy for backprojection and forward projection. NumPy writes a full-size temporary array for every operation, while the shader runs fused per element, compiled by LLVM to SIMD on every core.

Faster parallel-beam tools as a side effect

Because the projectors handle parallel beams too, existing electron tomography tools can use them. Weighted Back Projection and Generate Tilt Series can run on the shared projectors when a WebGPU adapter is available. In what we offer upstream this will be an opt-in setting: by default they keep running their original code.

Task (8 CPU threads, no GPU, lavapipe)BeforeNow
Weighted Back Projection, 512³, 71 tilts51 s12.2 s
Weighted Back Projection, bundled nanoparticle data6.45 s1.77 s
Generate Tilt Series, 256³, 71 tilts58.5 s3.5 s
SIRT, 60 iterations, 32×40×40 (vs NumPy)44 s1.4 s

The new WBP matches the original to float precision inside the field of view. These are software-GPU numbers. First real-GPU result, on an AMD Radeon RX 9070: cone-beam FDK of 600 walnut projections into 250³ voxels takes 5.2 s, against 18.4 s on lavapipe, with the results agreeing to 1.6×10−5 of the peak. That first run on real hardware also found and fixed a bug that only one GPU driver showed.

Results on real data

Lab cone-beam CT: a walnut

The Tomviz application window. On the left, the pipeline: walnut projections, flat and dark images, Flat/Dark Field Correction, Remove Ring Artifacts and Cone-Beam FDK. On the right, a 3D surface of the reconstructed walnut shell.
The whole chain in the Tomviz application: raw walnut projections with their flat and dark images, Flat/Dark Field Correction, Remove Ring Artifacts, and Cone-Beam FDK with the scanner's measured geometry, 600 projections into 250³ voxels of 0.2 mm. The surface is a contour at 0.05, between the kernel and the shell in the histogram above it.
Three orthogonal slices of a walnut. Top row: the dataset authors' reconstruction. Bottom row: the new Tomviz FDK. They look the same.
Walnut 1 of the CWI cone-beam collection, all 1200 projections, reconstructed into 501³ voxels. Top: the dataset authors' own reference reconstruction. Bottom: the new Cone-Beam FDK. Correlation 0.962, mean density within 2.1%. 255 s on lavapipe (software GPU, 8 threads).

With only 60 of the 1200 projections, FDK breaks up into streaks while SIRT still recovers the structure. In both images the top row is the full-data reference and the bottom row the reconstruction from 60 views, at 125³ voxels:

Walnut slices from 60 projections with FDK: streaky and noisy.
FDK from 60 views: correlation 0.872 with the reference.
Walnut slices from 60 projections with SIRT: much cleaner.
SIRT, 100 iterations, from 60 views: correlation 0.952, 59 s.

Ring artifacts

To test ring removal on real data, we added typical detector defects to the walnut's raw projections: small gain errors on 3% of the pixels, pixels with a slightly nonlinear response, clusters of neighbouring pixels, and a few dead pixels.

Three walnut slices: the clean reconstruction, the same with swirling ring artifacts from injected detector defects, and the corrected one, which looks like the clean one.
Left: reconstruction of the clean data. Middle: with the injected detector defects. Right: after Remove Ring Artifacts. 2.4 s for 600 projections of 486×384 pixels on 8 CPU threads.
MethodRing error leftChange to clean data
No correction0.2180
Tomviz (new)0.0470.020
TomoPy, filtering0.0740.020
TomoPy, sorting0.0900.041
TomoPy, remove_all_stripe0.2610.261

Errors are RMS differences from the clean reconstruction, in units of the walnut's density spread. The method is the filtering technique of Vo, Atwood and Drakopoulos (2018) on line integrals, plus repair of dead pixels. Their large-stripe detection was left out on purpose: on this data it flagged 7 to 20% of the pixels of clean data and left more error than no correction. The benchmark is dev/ring_bench.py in the branch.

Electron tomography: the bundled nanoparticle

Star-shaped nanoparticle reconstructed three ways; the two WBP results look identical, SIRT is cleaner.
The star nanoparticle tilt series that ships with Tomviz. Left: the original Weighted Back Projection. Middle: the same WBP on the shared projectors, 3.6 times faster and matching it inside the field of view. Right: parallel-beam SIRT on the same projectors. Top: slice across the tilt axis; bottom: along it.

Status

doneFlat/dark correction, −log, Cone-Beam FDK, Cone-Beam SIRT, shared projectors with WebGPU backend, faster WBP and Generate Tilt Series. Automated tests, including orientation checks against an analytic phantom and GPU-against-CPU agreement.
doneLinux .deb and AppImage packages for Tomviz, tested on Debian, Ubuntu and Rocky Linux, and on an AMD Radeon RX 9070 (branch).
doneRing artifact removal, chosen by benchmark on real data. All 76 tests pass on lavapipe and on an AMD Radeon RX 9070.
not yetSystematic timings on real GPUs from several vendors; the new operators checked in the built application; continuous integration with lavapipe.
laterReaders for scanner projection formats (for example Zeiss TXRM, Nikon XTEK), helical and other non-circular scans in the GUI, TV regularisation.

How it will go upstream

As small pull requests, each useful on its own and each with its own tests:

  1. Flat/dark field correction and the −log transform.
  2. The shared projectors (CPU) and Cone-Beam FDK.
  3. The WebGPU backend. This adds an optional dependency (wgpu), so we will open an issue to discuss it first.
  4. Weighted Back Projection and Generate Tilt Series on the shared projectors, as an opt-in.
  5. SIRT for cone and parallel beams.
  6. Ring artifact removal.

The packaging work goes to OpenChemistry/tomviz-packaging separately.

Design rules we hold to. Nothing tied to one machine, vendor or operating system. Every GPU path has a plain CPU reference it is tested against, and the GPU code is tested without GPU hardware, on a software driver. Existing operators keep their original code by default; the GPU path for them is opt-in.