Image Distance Transform

Description

This operator is used to calculate the distance between each foreground pixel (usually white pixels) and its nearest background pixel (black pixels) in a binary image. The output of the operator is a grayscale image, also known as a "distance map", where the brightness value of each pixel is proportional to its shortest distance to the background-the farther a pixel is from the background, the brighter it appears in the output image.

Overview

Calculates the distance from each foreground pixel to the nearest background pixel, outputting a distance map.

Scenarios

  • Object Center Localization: The brightest point in the distance map is the point farthest from all edges and can be considered the "center" of the object, often used as a seed point for segmentation algorithms.

  • Separating Touching Objects: When two objects touch or slightly overlap in a binary image, their distance maps usually remain separated. By applying a threshold to the distance map, the core region of each object can be extracted, thereby separating them.

  • Shape Feature Description: The distance map reflects the thickness information of the object and can be used to analyze the shape of the object.

Inputs and Outputs

Inputs

Binary image: One or a set of binary black and white images.

Outputs

Result image: The output distance grayscale image, where the intensity (grayscale value) of each pixel represents the distance from that point to the nearest background pixel.

Parameters

Distance Type

Description

This parameter defines the mathematical formula used to compute the "distance" between pixels. Different formulas produce slightly different distance maps.

Tuning Instructions

  • Euclidean distance: computed as D = √((x2−x1)² + (y2−y1)²), i.e., the straight-line distance between two points. Suitable for most scenarios that measure the shortest path between two points.

  • Manhattan distance: computed as D =

x2−x1

+

y2−y1

, also known as the "city block" distance — the distance traveled by moving only horizontally and vertically. Suitable for scenarios where movement is restricted to grid axes.

* Chebyshev distance: computed as D = max(

x2−x1

,

y2−y1

), also known as the "chessboard" distance. It equals the maximum difference along any single coordinate axis between two points.

Parameter Range

Values/Range:

  • Manhattan Distance

  • Euclidean Distance

  • Chebyshev Distance

Default: Euclidean Distance

Mask Size

Description

Sets the size of the internal algorithm mask used to approximate the distance calculation.

Tuning Instructions

The mask size affects the accuracy and speed of the distance computation. Using a "5×5" mask yields a more accurate distance estimate than a "3×3" mask, at a slightly higher computational cost. The default "5×5" mask size is generally recommended.

Note: When

Distance Type

is set to

Manhattan Distance

, this parameter is ignored and has no effect on the result.

Parameter Range

Values/Range:

  • 3x3

  • 5x5

Default: 5x5