ScientiaLux
strataquest Glossary Distance Maps
Spatial Tool

Distance Maps

Measuring spatial relationships between cells

View
Definition
How far is each point in the tissue from the nearest cell, the nearest tumor boundary, or the nearest blood vessel? Distance Maps compute the Euclidean distance from every pixel to the nearest object in a coded image, creating a continuous surface where each pixel's value represents its distance to the closest feature. These distance surfaces reveal spatial relationships that are invisible in the original image — proximity gradients, buffer zones, and separation distances between structures.
Pixel-to-Object Distance
How far is each point from the nearest object?
Inside and Outside Variants
Distance from both sides of the boundary
Proximity Analysis
Input for spatial statistics
Watershed Surface
Input for shape-based segmentation

How It Works

Distance Maps compute the Euclidean distance transform of a binary or coded image:

  1. Input — A coded image defines the objects. All non-zero pixels are "object"; zero pixels are "background."
  2. Distance computation — For each background pixel, compute the Euclidean distance to the nearest object pixel. For each object pixel, optionally compute the distance to the nearest background pixel (boundary distance).
  3. Output — A grayscale image where pixel intensity encodes distance. Background pixels near objects are dim (small distance); pixels far from objects are bright (large distance). Object pixels can encode their distance from the nearest boundary.

The Euclidean distance transform can be computed efficiently using a two-pass algorithm that processes rows then columns, achieving O(N) time for an N-pixel image despite the apparent O(N²) nature of the all-pairs distance problem.

Simplified

Distance Maps measure how far each pixel is from the nearest object. The result is a landscape where pixels close to objects have small values and pixels far away have large values. This simple transformation enables powerful spatial analysis — you can measure distances between any structures by reading values from each other's distance maps.

Science Behind It

Distance metrics (Gonzalez & Woods): Three common distance metrics for image analysis: Euclidean (D_e = √(Δx² + Δy²)) — the true straight-line distance, producing circular iso-distance contours; City block / Manhattan (D_4 = |Δx| + |Δy|) — the path along grid axes, producing diamond-shaped contours; Chessboard (D_8 = max(|Δx|, |Δy|)) — allows diagonal steps at unit cost, producing square contours. For biological spatial analysis, Euclidean distance is standard because cell-to-cell distances in tissue don't follow grid constraints.

The inside distance transform and shape: The inside distance transform of a convex object has a single peak at its center, with the peak value equal to the inscribed circle radius. For touching objects, the valley between their peaks indicates the contact region. This is why the negated inside distance transform serves as an ideal watershed input — each object's center is a local minimum (catchment basin), and the contact region is a ridge (watershed boundary). Solomon & Breckon note that the Euclidean distance transform "calculates distance from each background point to nearest foreground point" and when negated and used as a watershed surface, it performs shape-based segmentation.

Proximity zones and buffer analysis: Thresholding a distance map at a specific value creates a buffer zone — the set of all pixels within that distance of the objects. This is equivalent to morphological dilation by that distance but computed continuously rather than for a single integer value. A distance map thus encodes all possible dilation distances simultaneously, enabling flexible proximity analysis without rerunning the dilation at each distance.

Nearest-neighbor statistics: For two sets of objects (e.g., tumor cells and immune cells), the distance from each tumor cell's centroid to the nearest immune cell can be read directly from the immune cell distance map. The distribution of these nearest-neighbor distances characterizes the spatial relationship between the two populations: a narrow distribution centered on small distances indicates close spatial association; a wide distribution centered on large distances indicates spatial separation.

Simplified

The distance transform converts binary objects into continuous distance surfaces. Inside objects, the distance to the nearest boundary reveals shape (peaks at centers, valleys at thin connections). Outside objects, the distance reveals proximity relationships. This simple transformation enables powerful spatial analysis: finding all cells within 50 µm of the tumor boundary is just a threshold on the tumor distance map.

Parameters & Settings

ParameterTypeDescription
InputCoded imageObjects to compute distance from.
ModeOutside / InsideOutside: distance from background to nearest object. Inside: distance from object pixels to nearest boundary.
Maximum DistanceNumericCap the computed distance at this value (for efficiency and visualization).
Simplified

Choose Outside mode for proximity analysis (how far is each point from the nearest cell?) or Inside mode for shape analysis (how deep inside the object is each pixel?). Set Maximum Distance to limit computation to the relevant spatial range.

Practical Example

Analyzing immune cell infiltration as a function of distance from the tumor boundary:

  1. Create a tumor mask from CK+ cells (binary: tumor vs. non-tumor)
  2. Compute Outside Distance Map from the tumor mask → every pixel now encodes its distance from the nearest tumor cell
  3. Bin immune cells by their distance value: 0-20 µm, 20-50 µm, 50-100 µm, 100+ µm from tumor
  4. Compute immune cell density in each distance bin

Result: An immune infiltration profile showing how immune cell density changes with distance from the tumor boundary — high at the margin (immune-inflamed), low everywhere (immune-desert), or high only at distance (immune-excluded).

Simplified

Compute the distance from every point to the nearest tumor cell. Then measure immune cell density at different distances from the tumor — 0-20 µm, 20-50 µm, 50-100 µm. The resulting profile shows whether immune cells are infiltrating the tumor, crowding at the boundary, or excluded entirely.

Connected Terms

Share This Term
Term Connections