Home

From Medical Scan to 3D Model

A grid of 36 axial CT slices through a head, from the crown down to the jaw: the first three columns in greyscale, the middle three with the bone filled in orange, the last three showing only teal bone outlines
Axial CT slices through one head, read left to right: the scan, the bone label, the extracted outlines. CT: TotalSegmentator dataset, CC BY 4.0.

A CT or MRI scan is not a 3D model. It is a stack of grey images: a volume of voxels, each holding a single number. A 3D printer wants something else entirely: a closed surface made of triangles, usually as an STL file. Getting from one to the other takes six steps, and each of them has a way of going wrong quietly.

Step Turns … What goes wrong
1. Read DICOM files into a volume wrong series, wrong spacing, mirrored axes
2. Segment intensities into a mask thin bone lost, soft tissue swallowed
3. Combine several scans into one trusting coordinates that don't agree
4. Extract voxels into triangles staircases, inside-out meshes
5. Finish a raw surface into a clean one smoothing that shrinks the model or erases detail
6. Validate a surface into a printable model holes, flipped faces, self-intersections
From slices to a surface: the slices stack up, the bone is outlined in each one, the outlines become a volume of voxels, and a triangle mesh is wrapped around it. CT: TotalSegmentator dataset, CC BY 4.0.

1. Read the data correctly

Diagram: a CT study folder branches into four series (scout, thick soft-tissue axial, thin bone-kernel axial, coronal reformat); the thin bone-kernel series is selected and connects to a list of the key DICOM tags in one slice file
A CT study usually holds several series. Only one of them is the volume you want, and every slice file carries the geometry that places it.

A CT study arrives as a folder of DICOM files, typically one file per slice, and almost always with more than one series: a scout image used to plan the scan, thin and thick reconstructions, soft-tissue and bone kernels, sometimes reformats in other planes. Pick the thinnest complete axial series reconstructed with a bone (sharp) kernel. The others are too coarse, derived from it, or not a volume at all.

Geometry comes from the file headers, not from the pixel grid. Each slice records where it sits (ImagePositionPatient) and which way it faces (ImageOrientationPatient), and PixelSpacing gives the in-plane pixel size. Derive the distance between slices from their positions, not from SliceThickness: that tag describes how thick each slice was reconstructed, which is often not how far apart the slices are. Check for gaps, duplicate positions, uneven spacing and gantry tilt, which shears the whole stack.

Two mistakes here produce models that look fine and are wrong. DICOM uses the LPS patient coordinate system (x toward the patient's left, y toward the back, z toward the head), while many NIfTI tools assume RAS. Getting the conventions or the slice order wrong flips axes, and a single flipped axis mirrors the model, which on a nearly symmetric skull is easy to miss. And when the index-to-world matrix is left-handed (negative determinant), triangles built in index space end up wound the wrong way once transformed: the mesh is inside out unless you reverse them.

The stored pixel values are not Hounsfield units yet. HU = stored value × RescaleSlope + RescaleIntercept. On that scale, air is −1000 and water is 0 by definition, fat sits around −100, soft tissue a little above water, and bone anywhere from a few hundred to well over a thousand.

Log-scale histogram of CT values from −1000 to 2000 HU with shaded bands for air, fat, soft tissue and bone; sharp peaks at air, fat and soft tissue and a long declining tail through the bone range
Histogram of a whole-body CT in Hounsfield units. Air, fat and soft tissue form clear peaks; bone is a long tail, not a peak. CT: TotalSegmentator dataset, CC BY 4.0.

This calibration exists only for CT. MRI and cone-beam CT have no fixed intensity scale, so any threshold that assumes HU means nothing there.

Then convert the series into a single self-describing volume (NIfTI, NRRD or MetaImage) that keeps spacing, origin and direction, and read it back once to confirm nothing changed. Mind privacy while you're at it: DICOM headers carry names, birth dates and IDs, and the skin surface of a head CT is, quite literally, a face.

What makes a scan printable

Two coronal CT slices through the eyes and sinuses side by side; the left one is sharp, the right one, made from thicker slices, is blocky and its thin bone walls are faint
The same coronal slice at 1.5 mm and at 4.5 mm slice thickness. Thick slices turn curves into terraces, and the thin bone around the eyes and sinuses fades into its surroundings. CT: TotalSegmentator dataset, CC BY 4.0.

A scan can be excellent for diagnosis and still poor for printing. What helps:

  • slices under 1 mm, with no gaps between them
  • pixels under 0.5 mm
  • a bone (sharp) reconstruction kernel
  • no gantry tilt
  • no lossy compression

The reason is the partial-volume effect. A voxel that is half bone and half soft tissue gets an average value, so bone thinner than a voxel or two never reaches full bone intensity and drops below any sensible threshold. One rule holds for everything that follows: a print never contains more detail than the scan it came from.

2. Segment: decide which voxels are bone

Four copies of a sagittal head CT slice: with a low threshold most of the head is orange; with a medium one only the bone; with a high one the bone breaks into fragments; the fourth shows coloured labels for skull, vertebrae, brain and other structures
One sagittal slice, segmented three times by threshold and once by TotalSegmentator. A threshold trades soft-tissue leaks against holes in thin bone; the AI labelmap keeps structures apart. CT: TotalSegmentator dataset, CC BY 4.0.

The simplest segmentation is a threshold: every voxel above some HU value counts as bone. Too low, and soft tissue, contrast-filled vessels and noise leak in. Too high, and thin bone breaks up into holes, exactly where it is most delicate: the orbits, the sinus walls, the nasal septum. For data without HU calibration, Otsu's method picks the threshold that best splits the histogram into two classes. It is a reasonable start, nothing more.

A raw threshold mask always needs cleanup:

  • a median filter against speckle noise
  • morphological opening to remove specks and thin bridges, and closing to fill small gaps
  • connected components to drop islands: the scanner table, noise, streaks from metal
  • hole filling for enclosed cavities you don't want

Define these kernels in millimetres, not voxels. CT voxels are rarely cubes, and a three-voxel kernel means something different along each axis.

The modern alternative is AI segmentation. TotalSegmentator, an open-source model built on nnU-Net, labels more than 100 anatomical structures in CT and has a model for MRI as well. Its output is a labelmap, one integer per voxel and one label per structure, so skull, vertebrae, brain and vessels stay separable instead of merging into one blob above a threshold.

It still makes mistakes, so plan for manual correction, and do it in the volume, voxel by voxel, before any mesh exists. Painting a few cubes is easy. Untangling a surface of millions of triangles is not.

3. Combine scans (optional)

Two side views of a skull silhouette built from two partial scans: on the left the upper scan is tilted and shifted against the lower one; on the right they line up and their overlap forms a clean band
Illustration: two partial scans of the same head before and after rigid alignment. Registration aligns the bone both scans share. CT: TotalSegmentator dataset, CC BY 4.0.

One scan rarely covers everything. A facial CT may stop above the eyebrows, a sinus CT may leave out the lower jaw. Two scans of the same person can be merged, but not by trusting their coordinates: every session has its own patient position, and the coordinates of two series agree only by accident.

The standard approach is rigid registration on the shared anatomy. Bone doesn't deform between scans, so a rotation plus a translation is the right model. A coarse alignment comes first, for example by cross-correlating the two bone masks to find the best shift. Iterative closest point (ICP) then refines it on surface points; the point-to-plane variant converges far faster than point-to-point on smooth anatomy.

Check the result before you trust it. Measure the overlap, for example the Dice coefficient of the two masks inside the region both scans cover, and refuse to merge when it is poor. Watch for one classic trap: an initial alignment from principal axes or an SVD can produce a reflection instead of a rotation. A mirrored jaw fits a jaw remarkably well, so a good fit score proves nothing. Require a determinant of +1.

Finally, resample both masks onto one shared isotropic grid and take their union.

4. Extract the surface: marching cubes

Three pixel grids with the same blob: filled pixels with a staircase outline; a contour through pixel centres with 45-degree chamfers; and a smooth contour that closely follows the dashed true outline
Marching squares, the 2D version of marching cubes. On a binary mask the contour can only cut corners; on partial-volume occupancy it follows the true shape (dashed) closely.

Marching cubes turns a volume into triangles. It visits every cube formed by eight neighbouring voxel centres, checks which corners are inside, and places triangles where the isosurface crosses the cube's edges, interpolating along each edge. On a binary mask every crossing lands exactly halfway, so the surface can only trace the voxel staircase with chamfered corners. On a smooth field, such as intensities or occupancy averaged over each voxel, the crossings slide along the edges and the surface follows the anatomy far more closely.

Two details decide whether the result is in the right place. The vertices come out in index space and must be mapped through the volume's index-to-world transform, minding whether a voxel coordinate means its corner or its centre: a half-voxel slip shifts the whole model. And, as above, a left-handed transform flips the triangle winding.

Expect big meshes, often millions of triangles for a skull. Blurring the mask before extraction reduces the staircase, but it can also close narrow gaps and erase thin bone, and the mesh that comes out is still perfectly valid. Nothing downstream will warn you.

5. Finish the surface

Four outlines of a dome with a narrow crest: the raw outline is terraced; Laplacian smoothing shrinks it and loses the crest; Taubin smoothing keeps the size but flattens the crest; masked fairing is smooth and keeps the crest
A 2D profile through a terraced surface, smoothed three ways. The dashed line is the true shape.

Raw marching-cubes surfaces need smoothing, and the obvious method is the wrong one. Laplacian smoothing moves every vertex toward the average of its neighbours. It removes terraces, but it also shrinks the model and rounds off every ridge. Taubin smoothing alternates a shrinking step with a slightly stronger inflating one and keeps the size intact. Push it hard enough to remove broad terraces, though, and fine detail goes flat with them.

Two habits help. First, measure the defect before you choose a filter. Terraces from thick slices often show up as broad, shallow waves many millimetres apart rather than as steps at the slice spacing, and a filter tuned to the voxel size won't touch them. Second, smooth selectively: fair broad, gently curved regions strongly, freeze tightly curved detail such as orbital rims and teeth together with a margin around it, and cap how far any vertex may move.

Then reduce the triangle count. Quadric-error decimation collapses edges where that changes the shape least; give it an error bound in millimetres. Every one of these steps can introduce self-intersections or flipped faces, so check after each one and repair the damage locally instead of assuming it went well.

6. Validate before printing

Six small 3D renders: a closed sphere; a sphere with a hole outlined in orange; three faces sharing one edge; a patch with one face whose normal points down; two sheets crossing each other; a closed plate with a tunnel through it
What a printable mesh must not have, and one defect no geometric check will catch.

A printable mesh is:

  • watertight, with no holes and no boundary edges
  • manifold, with every edge shared by exactly two faces
  • consistently oriented, with every normal pointing outward
  • free of self-intersections
  • enclosing a positive volume

Several separate closed shells are fine; a skull and a loose vertebra can share one file. Where the scan's field of view ends, the surface is open by construction, so cap those openings. For export, STL is the common denominator: loose triangles without shared vertices and without units, which are millimetres by convention. PLY and OBJ keep shared vertices, and 3MF also records units.

Keep one limit in mind: validation checks geometry, not anatomy. A smoothing step that punches a tunnel through thin bone still produces a closed, manifold, outward-facing mesh. Only comparing the result against the scan catches that.

Beyond CT: merging surface scans

Left: the outline of a CT tooth wall wavers across the straight wall of a scanned crown, leaving thin white slivers between them. Right: a distance field with one smooth outline that follows the scan above and the CT below
Merging a sharp surface scan into a blurry CT tooth. A mesh boolean leaves slivers where the two surfaces nearly coincide; one blended distance field yields one clean surface.

CT blurs small structures such as teeth into soft lumps. Intraoral or optical surface scans capture them sharply, but as open surfaces with the gums attached, each in its own coordinate system. To combine them, register each scan to the matching CT anatomy, keep only the part you want (the crowns, cut from the gum along the concave crease of the gumline), and then merge.

Avoid mesh booleans for that last step. The two surfaces nearly coincide along the tooth walls, and booleans on near-coincident surfaces leave slivers, seams and self-intersections. Instead, describe both shapes as signed distance fields on a fine grid, blend them so that the scan owns the crowns and the CT owns everything else with a smooth transition in between, and extract a single surface from the result.

Printing notes

  • Compare the thinnest walls with your printer's minimum. Orbital walls and nasal structures are often below it.
  • Hollow regions such as the skull vault need internal supports, and those supports have to come out again.
  • Resin prints capture fine detail; filament (FDM) prints are cheaper and tougher.

Script it

None of these steps is exotic, but each one fails quietly: a flipped axis, a threshold that eats thin bone, a smoothing pass that shrinks the model, a valid mesh with a tunnel through it. The best defence is to script the whole path instead of clicking through it. A better scan then means rerunning the pipeline rather than redoing evenings of manual repair, and every intermediate result can be inspected and compared.

Models made this way are for education, visualization and curiosity. They are not a basis for diagnosis or treatment planning.

Credits. The CT data in the header, the figures and the animation is subject s1045 from Jakob Wasserthal (2023), "Dataset with segmentations of 117 important anatomical structures in 1228 CT images", version 2.0.1, Zenodo, doi:10.5281/zenodo.10047292, licensed under CC BY 4.0. It was cropped, resampled and rendered for this post.