// blog

DICOM Pixel Spacing: How a Viewer Measures in Millimeters

Pixel Spacing (0028,0030) holds two decimal numbers in millimeters: the distance between the centers of adjacent rows, then of adjacent columns, for example 0.9765625\0.9765625 on a CT. A distance in pixels times the spacing gives millimeters. On projection X-rays, Imager Pixel Spacing (0018,1164) is measured at the detector, where the body appears slightly magnified, so millimeter measurements on X-rays are approximate unless they’re calibrated.

Last updated 2 min read

Pixel Spacing: a chest CT with a measuring line and the label 0.9765625 mm per pixel

Draw a line across a scan in a DICOM viewer and it tells you the length in millimeters. All of that comes from one element in the file: Pixel Spacing.

What it holds

Pixel Spacing is tag (0028,0030), value representation DS (a decimal number stored as text), with two values separated by a backslash:

text
(0028,0030) DS [0.9765625\0.9765625]   PixelSpacing

That’s our chest CT sample. The first value is the row spacing, the distance in millimeters between the centers of two neighboring rows; the second is the column spacing. Here each pixel covers just under a millimeter: 512 pixels × 0.9765625 mm is a 500 mm field of view.

Turning a line into millimeters

A line from pixel (x1, y1) to (x2, y2) is:

js
const [rowSpacing, colSpacing] = pixelSpacing; // mm
const dx = (x2 - x1) * colSpacing;              // columns run horizontally
const dy = (y2 - y1) * rowSpacing;              // rows run vertically
const mm = Math.hypot(dx, dy);

Mind the order: rows first, then columns, which is the opposite of the usual “x, y”. When both values are equal it doesn’t matter, and bugs hide until a file with non-square pixels arrives.

That’s what the Measure tool in our viewer does with the file’s own spacing.

X-rays are different

A CT or MRI slice is a cross-section, so its spacing is the size in the patient. A projection X-ray is a shadow: the body sits between the X-ray tube and the detector, so it appears slightly larger on the detector than it is.

  • Imager Pixel Spacing (0018,1164) is the spacing at the detector.
  • Pixel Spacing (0028,0030), when present on an X-ray, may be corrected or calibrated; Pixel Spacing Calibration Type (0028,0A02) says whether it was.
  • Estimated Radiographic Magnification Factor (0018,1114) helps estimate the size in the patient.

So a millimeter measurement on an X-ray is an approximation unless the file says it was calibrated. A careful viewer shows which spacing it used.

Ultrasound

Ultrasound images often have no Pixel Spacing at all. Their calibration lives in the Sequence of Ultrasound Regions (0018,6011), one region per area of the screen, with Physical Delta X and Y for each. A viewer that measures on ultrasound has to find the region the line is in.

When you change the image

Resize an image and the spacing changes with it. When we scaled our X-ray samples down for the web, DCMTK’s dcmscale rewrote their spacing to match, so the measurements still come out in millimeters. Any code that resizes, crops or reformats images has to keep the spacing honest.

Key takeaways

  • (0028,0030) Pixel Spacing: row spacing, then column spacing, in mm.
  • Distance = Δcolumns × column spacing and Δrows × row spacing, then Pythagoras.
  • X-rays: Imager Pixel Spacing is at the detector; check the calibration before trusting millimeters.
  • Resizing changes the spacing; update it.

Measure on a CT in the browser →

We’re glad to share what we know. When you want a viewer or portal of your own, we’ll put all of it to work on your project, and because we build with AI-assisted development, it costs far less than you might expect. Let’s talk.

Frequently asked questions

Which number is rows and which is columns?

The first value is the spacing between rows (the vertical distance between pixel centers), the second between columns (the horizontal distance). They're often equal, but don't assume it: use the first for vertical steps and the second for horizontal ones.

What if a file has no Pixel Spacing?

Then the viewer can't measure in millimeters and should say so, measuring in pixels instead. Ultrasound images often store their calibration elsewhere, in the Sequence of Ultrasound Regions (0018,6011).

Does resizing an image change its Pixel Spacing?

Yes. Halve the size and each pixel covers twice the distance. Tools like DCMTK's dcmscale update the spacing when they scale an image; your own code has to as well.

Sources

  1. DICOM PS3.3: Image Plane Module (Pixel Spacing)
  2. DICOM PS3.3: Pixel Spacing and related attributes (10.7.1)