A distance map, also known as distance transform, is a representation of an image where each pixel value
corresponds to its distance to the nearest boundary pixel in a given metric.
Two metrics are commonly used:
The Chessboard distance, also known as Chebyshev distance, where all neighbor pixels are considered as a
same distance of 1 from a given pixel.
The Chamfer distance where edge neighbors are considered as a distance of 1 and corner neighbors are
considered with a √2 weight in order to better approximate a Euclidean distance.
In the output image O, a pixel x belonging to a particle X, takes an intensity I equal to
the distance to the boundary.
In the case of the Chessboard metric, the distance is given by: I=dC(x,δ(X))
Where: dC((i,j),(h,k))=max(|h−i|,|k−j|)
The weight used for each neighbor configuration can be user defined. Some optimizations are automatically
performed when the weights set correspond to a Chamfer or a Chessboard distance map.
Distance maps are computed on binary images either on object pixels (foreground) or on the background.
The output image can have either a 16-bit signed integer or a 32-bit float type.
Figure 1. Output image for chessboard distance transform in inside mode
Figure 2. Output image for chamfer distance transform in inside mode
Note: This algorithm does not take into account the input image calibration. The output values
are systematically indicating distance in pixel units.
// Command constructor.DistanceMap2d();/// Gets the inputBinaryImage parameter./// The binary input image.
std::shared_ptr< iolink::ImageView> inputBinaryImage()const;/// Sets the inputBinaryImage parameter./// The binary input image.void setInputBinaryImage( std::shared_ptr< iolink::ImageView> inputBinaryImage );/// Gets the mappingMode parameter./// The mode defining where the distance field is computed.DistanceMap2d::MappingMode mappingMode()const;/// Sets the mappingMode parameter./// The mode defining where the distance field is computed.void setMappingMode(constDistanceMap2d::MappingMode& mappingMode );/// Gets the borderCondition parameter./// The mode defining the border conditions.DistanceMap2d::BorderCondition borderCondition()const;/// Sets the borderCondition parameter./// The mode defining the border conditions.void setBorderCondition(constDistanceMap2d::BorderCondition& borderCondition );/// Gets the edgeDistance parameter./// The distance weight between 2 pixels having an edge connection.double edgeDistance()const;/// Sets the edgeDistance parameter./// The distance weight between 2 pixels having an edge connection.void setEdgeDistance(constdouble& edgeDistance );/// Gets the cornerDistance parameter./// The distance weight between 2 pixels having a corner connection.double cornerDistance()const;/// Sets the cornerDistance parameter./// The distance weight between 2 pixels having a corner connection.void setCornerDistance(constdouble& cornerDistance );/// Gets the outputType parameter./// The output image type to provide.DistanceMap2d::OutputType outputType()const;/// Sets the outputType parameter./// The output image type to provide.void setOutputType(constDistanceMap2d::OutputType& outputType );/// Gets the outputMapImage parameter./// The output distance map image.
std::shared_ptr< iolink::ImageView> outputMapImage()const;/// Sets the outputMapImage parameter./// The output distance map image.void setOutputMapImage( std::shared_ptr< iolink::ImageView> outputMapImage );// Method to launch the command.void execute();
# Property of the inputBinaryImage parameter.DistanceMap2d.input_binary_image
# Property of the mappingMode parameter.DistanceMap2d.mapping_mode
# Property of the borderCondition parameter.DistanceMap2d.border_condition
# Property of the edgeDistance parameter.DistanceMap2d.edge_distance
# Property of the cornerDistance parameter.DistanceMap2d.corner_distance
# Property of the outputType parameter.DistanceMap2d.output_type
# Property of the outputMapImage parameter.DistanceMap2d.output_map_image
// Method to launch the command.
execute()
// Command constructor.DistanceMap2d()// Property of the inputBinaryImage parameter.DistanceMap2d.inputBinaryImage
// Property of the mappingMode parameter.DistanceMap2d.mappingMode
// Property of the borderCondition parameter.DistanceMap2d.borderCondition
// Property of the edgeDistance parameter.DistanceMap2d.edgeDistance
// Property of the cornerDistance parameter.DistanceMap2d.cornerDistance
// Property of the outputType parameter.DistanceMap2d.outputType
// Property of the outputMapImage parameter.DistanceMap2d.outputMapImage
// Method to launch the command.Execute()
Parameters
Parameter Name
Description
Type
Supported Values
Default Value
inputBinaryImage
The binary input image.
Background is represented by zero values while objects are represented by one values.
Image
Binary
nullptr
mappingMode
The mode defining where the distance field is computed.
INSIDE
Distances are computed for pixels inside the objects (having an intensity equal to 1). Outside pixels remain to zero.
OUTSIDE
Distances are computed for pixels outside of objects (having an intensity equal to 0). Inside pixels are set to zero.
Enumeration
INSIDE
borderCondition
The mode defining the border conditions.
ZERO
Pixels outside of the image are considered to have the value 0.
MIRROR
Pixels outside of the image are considered as an extrapolation of the image pixels with a mirror border condition.
Enumeration
MIRROR
edgeDistance
The distance weight between 2 pixels having an edge connection.
The value must be strictly positive.
Float64
>0
1
cornerDistance
The distance weight between 2 pixels having a corner connection.
The value must be greater than or equal to edgeDistance.
Float64
Any value
1.41421
outputType
The output image type to provide.
SIGNED_INTEGER_16_BIT
The output image type is 16-bit signed integer.
FLOAT_32_BIT
The output image type is 32-bit float.
Enumeration
SIGNED_INTEGER_16_BIT
outputMapImage
The output distance map image.
The distance map of the shape represented by the input image. Each voxel is assigned to a value
corresponding to the distance to the nearest object boundary. Its dimensions are forced to the same values
as the input. Its data type is defined by the outputType parameter.
Image
nullptr
Parameter Name
Description
Type
Supported Values
Default Value
input_binary_image
The binary input image.
Background is represented by zero values while objects are represented by one values.
image
Binary
None
mapping_mode
The mode defining where the distance field is computed.
INSIDE
Distances are computed for pixels inside the objects (having an intensity equal to 1). Outside pixels remain to zero.
OUTSIDE
Distances are computed for pixels outside of objects (having an intensity equal to 0). Inside pixels are set to zero.
enumeration
INSIDE
border_condition
The mode defining the border conditions.
ZERO
Pixels outside of the image are considered to have the value 0.
MIRROR
Pixels outside of the image are considered as an extrapolation of the image pixels with a mirror border condition.
enumeration
MIRROR
edge_distance
The distance weight between 2 pixels having an edge connection.
The value must be strictly positive.
float64
>0
1
corner_distance
The distance weight between 2 pixels having a corner connection.
The value must be greater than or equal to edgeDistance.
float64
Any value
1.41421
output_type
The output image type to provide.
SIGNED_INTEGER_16_BIT
The output image type is 16-bit signed integer.
FLOAT_32_BIT
The output image type is 32-bit float.
enumeration
SIGNED_INTEGER_16_BIT
output_map_image
The output distance map image.
The distance map of the shape represented by the input image. Each voxel is assigned to a value
corresponding to the distance to the nearest object boundary. Its dimensions are forced to the same values
as the input. Its data type is defined by the outputType parameter.
image
None
Parameter Name
Description
Type
Supported Values
Default Value
inputBinaryImage
The binary input image.
Background is represented by zero values while objects are represented by one values.
Image
Binary
null
mappingMode
The mode defining where the distance field is computed.
INSIDE
Distances are computed for pixels inside the objects (having an intensity equal to 1). Outside pixels remain to zero.
OUTSIDE
Distances are computed for pixels outside of objects (having an intensity equal to 0). Inside pixels are set to zero.
Enumeration
INSIDE
borderCondition
The mode defining the border conditions.
ZERO
Pixels outside of the image are considered to have the value 0.
MIRROR
Pixels outside of the image are considered as an extrapolation of the image pixels with a mirror border condition.
Enumeration
MIRROR
edgeDistance
The distance weight between 2 pixels having an edge connection.
The value must be strictly positive.
Float64
>0
1
cornerDistance
The distance weight between 2 pixels having a corner connection.
The value must be greater than or equal to edgeDistance.
Float64
Any value
1.41421
outputType
The output image type to provide.
SIGNED_INTEGER_16_BIT
The output image type is 16-bit signed integer.
FLOAT_32_BIT
The output image type is 32-bit float.
Enumeration
SIGNED_INTEGER_16_BIT
outputMapImage
The output distance map image.
The distance map of the shape represented by the input image. Each voxel is assigned to a value
corresponding to the distance to the nearest object boundary. Its dimensions are forced to the same values
as the input. Its data type is defined by the outputType parameter.