几种常见距离
距离变换主要分为欧氏距离变换和非欧氏距离变换。 非欧距离变换包括棋盘距离变换、城市街区距离变换和倒角距离变换。
切比雪夫距离(Chebyshev Distance)也叫棋盘距离:| x1 - x2 | + | y1 - y2 |
L1距离、曼哈顿距离,也叫城市街区距离:max( | x1 - x2 |, | y1 - y2 | )
API
基于ITK 5.4.0文档
SignedDanielssonDistanceMapImageFilter
Danielsson 距离是一种逐步扩展的算法
SignedMaurerDistanceMapImageFilter
Maurer 距离是一种基于队列的算法
ApproximateSignedDistanceMapImageFilter
Chamfer distances(倒角距离),速度较快
衡量两个形状之间的差异性或相似性,常用于特征点匹配、图像分割
DanielssonDistanceMapImageFilter
SignedDanielsson外部的负数变正数
FastChamferDistanceImageFilter
快速倒角变换
IsoContourDistanceImageFilter
计算网格点到等轮廓线的距离
SimpleITK实现
import SimpleITK as sitk
import os
# 加载二值图像
input_image_path = "mask_image.mha"
input_image = sitk.ReadImage(input_image_path)
# distance_map = sitk.SignedMaurerDistanceMap(input_image, insideIsPositive=True, squaredDistance=False, useImageSpacing=True)
# output_image_path = "signedMaurer.mha"
# sitk.WriteImage(distance_map, output_image_path)
# distance_map = sitk.SignedDanielssonDistanceMap(input_image, insideIsPositive=True, squaredDistance=False) # 计算的距离绝对值
# output_image_path = "signedDanielsson.mha"
# sitk.WriteImage(distance_map, output_image_path)
# sitk.ApproximateSignedDistanceMap
distance_map = sitk.DanielssonDistanceMap(input_image)
output_image_path = "Danielsson.mha"
sitk.WriteImage(distance_map, output_image_path)
效果