| Customize Help

Distance transform



You can produce a distance transform using MimDistance(). This function determines the minimum distance from each foreground (non-zero) pixel to a background (zero) pixel, and assigns this distance to the foreground pixel. It produces a type of contour mapping of an image's foreground (object) pixels.

You can calculate the minimum distance using one of three transforms:

  • City Block transform.

  • Chessboard transform.

  • Chamfer 3-4 transform.

City Block transform

The City Block transform (M_CITY_BLOCK) determines the minimum distance using only horizontal or vertical steps. Each step counts as 1.

Chessboard transform

The Chessboard transform (M_CHESSBOARD) determines the minimum distance using horizontal, vertical, or diagonal steps. Each step counts as 1.

Chamfer 3-4 transform

The Chamfer 3-4 transform (M_CHAMFER_3_4), like the Chessboard transform, determines the minimum distance using horizontal, vertical, or diagonal steps. However, horizontal and vertical steps are counted as 3 and diagonal steps as 4. This allows the transform to better approximate the true (Euclidean) distance between two pixels. However, it requires that the destination buffer be large enough to hold a number at least three times the maximum distance from a foreground to a background pixel. For example, an 8-bit buffer (255 max) can be used for a maximum distance of 85 pixels and a 16-bit buffer (65535 max) for a maximum distance of 21845 pixels.