🟧 Image Distance Transform
Function Description
This operator calculates the distance between each foreground pixel (usually white pixels) and its nearest background pixel (black pixels) in a binary image. The output is a grayscale image, also called a "distance map", where each pixel’s brightness value 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.
Usage Scenarios
-
Object center positioning: The brightest point in the distance map is the point farthest from all edges, which can be considered the "center" of the object and is often used as seed points for segmentation algorithms.
-
Separating touching objects: When two objects touch or slightly overlap in a binary image, their distance maps are usually still separate. By applying a threshold to the distance map, the core regions of each object can be extracted, thus separating them.
-
Shape feature description: Distance maps reflect thickness information of objects and can be used to analyze object shapes.
Input Output
Input |
Binary Image: One or more binary black and white images. |
Output |
Result Image: Output distance grayscale image where each pixel’s intensity (grayscale value) represents the distance from that point to the nearest background pixel. |
Parameter Description
Distance Type
Parameter Description |
This parameter defines the mathematical formula used when calculating "distance" between pixels. Different formulas will produce slightly different distance maps. |
Parameter Adjustment |
|
Mask Size
Parameter Description |
Set the size of the internal algorithm mask used for approximate distance calculation. |
Parameter Adjustment |
Mask size affects the accuracy and speed of distance calculation. Using a "5x5" mask will get more accurate distance estimates than using a "3x3" mask, but computational cost will be slightly higher. Generally recommend using the default "5x5" mask size. Note: When "Distance Type" is selected as "Manhattan Distance", this parameter will be ignored and will not affect results. |