Skip to content

Chapter 2 — Geometry, segmentation and resampling

This chapter · ~3 h total across 8 lessons · The chapter where most serious quantitative bugs live · Energy: low to active · Setup: Python (pydicom, numpy, SimpleITK) + RIDER data for the hands-on lessons

If Chapter 1 asked what a CT pixel is, this chapter asks where that pixel sits in the patient. Almost every serious bug in quantitative imaging — a mask that lands on the wrong anatomy, a feature that changes for no apparent reason, a validation that silently leaks — is a geometry bug wearing a disguise. This is the chapter to read most carefully.

The thread this chapter pulls

A NumPy array is a box of numbers. It has no idea where it is in the patient, how big a voxel is, or which way is up. To do any quantitative work you must attach a physical geometry to it: an origin, a spacing, and a direction. That geometry is what lets a CT and a segmentation occupy “the same space”, what lets you stack slices into a volume, and what makes resampling anything other than a silent warp.

The chapter builds that geometry from the ground up:

  • why array indices and physical patient coordinates are different things, and the affine that connects them;
  • the DICOM row/column trap that transposes people by accident;
  • how to order slices geometrically — never by filename or InstanceNumber;
  • what FrameOfReferenceUID actually proves (and does not);
  • why a SEG, an RTSTRUCT and a binary mask are not the same object;
  • why images resample with interpolation but masks must resample nearest-neighbour, and why that choice changes every boundary feature;
  • a real Visual-QC pass in 3D Slicer that turns all of this into something you can see.

Lessons

  1. The NumPy array has no physical location — index space vs patient space.
  2. How a voxel gets an (x,y,z) position — origin, spacing, direction, the affine, a worked numeric example.
  3. The DICOM row/column trap — IOP, PixelSpacing, NumPy vs SimpleITK.
  4. Order slices without trusting filenames — the slice normal and geometric ordering.
  5. When CT and segmentation really share space — FrameOfReferenceUID, geometry checks, registration.
  6. SEG, RTSTRUCT and binary masks are not the same — representation and what each silently loses.
  7. Why image and mask resampling must differ — linear/B-spline vs nearest-neighbour.
  8. Visual QC: prove the mask is where you think — a hands-on Slicer pass on a RIDER case.

Dense reference material — the IOP/IPP equations, the SimpleITK bridge, the full failure-mode catalogue and the TRACE-CT code map — lives in the geometry reference.

How this chapter connects

  • It assumes Chapter 1 (the file’s contract: UIDs, slope/intercept, series grouping).
  • Chapter 3 treats a radiomic feature as a function of (image, mask, geometry) — every geometry decision here is a feature-determining variable there.
  • Chapter 4 reuses the geometry to define leakage (a patient’s scans must not cross folds).

If you only have an hour, lessons 1–2 (the affine) and lesson 4 (slice ordering) are the core; everything else refines or applies them.