Statistical Methods

Measure Distance to Background with the Correct Pixel Spacing

Define the task

A binary distance transform replaces each foreground cell with its shortest distance to a background cell. Specify which values mean foreground and background before calculating. Keep row and column spacings in the same physical units; unequal spacing changes Euclidean geometry. The tool requires an in-array zero and measures between sampled cell centers. It does not add a virtual background outside the array or infer a continuous boundary.

Carry out the check

Check a few distances by hand using sqrt((row difference × row spacing)²+(column difference × column spacing)²). Retain the mask version and crop extent. Changing either can change the nearest background point. A maximum distance is not automatically a diameter or a tissue-thickness estimate. Such interpretations need a separate geometric definition and validation. All-foreground arrays are rejected here instead of relying on library-specific edge behavior.

Worked hypothetical example

Hypothetical example: use rows [0,1,1], [1,1,1], with row spacing 2 and column spacing 1. The distance at row 1, column 1 is sqrt(5), about 2.2361, because the only background cell is (0,0). The farthest cell (1,2) is sqrt(8), about 2.8284, away. Background itself has distance zero. Swapping the spacing order changes these values and should be caught before reporting physical measurements.

Method checked 23 November 2026 against Primary method documentation: distance_transform_edt.

Open the grid background distance.

Download the image distance spacing worksheet.

Related reading

Reading path: Analyze data. Guide 204 of 212. Choose any guide to suit your project.

Statistical Methods

Decide Which Enclosed Background a Mask May Fill

Practical steps and a hypothetical example: Audit enclosed background before changing a binary mask.

Statistical Methods

Separate Empirical Energy Distance from an Energy Test

Practical steps and a hypothetical example: Compare empirical distributions using pairwise absolute distances.

Browse this reading pathTools for this stageGuides and downloads for this stage