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.