对应头文件:
#include <opencv2/imgproc.hpp>
函数功能:
计算源图像的每个像素到最近的零像素的距离。函数 cv::distanceTransform 计算从每个二进制图像像素到最近的零像素的近似或精确距离。 对于零图像像素,距离显然为零。
distanceTransform() [1/2]
c++格式
void cv::distanceTransform ( InputArray src,
OutputArray dst,
OutputArray labels,
int distanceType,
int maskSize,
int labelType = DIST_LABEL_CCOMP
)
python格式:
cv.distanceTransform( src, distanceType, maskSize[, dst[, dstType]] ) -> dst
cv.distanceTransformWithLabels( src, distanceType, maskSize[, dst[, labels[, labelType]]] ) -> dst, labels
参数定义:
src 8-bit, single-channel (binary) source image.
----8位单通道二值图像(0-255)
dst Output image with calculated distances. It is a 8-bit or 32-bit floating-point, single-channel image of the same size as src.
----计算距离后的输出图像,8位或32位浮点型的单通道图像
labels Output 2D array of labels (the discrete Voronoi diagram). It has the type CV_32SC1 and the same size as src.
----标签的二维输出数组
distanceType Type of distance, see DistanceTypes
maskSize Size of the distance transform mask, see DistanceTransformMasks. DIST_MASK_PRECISE is not supported by this variant. In case of the DIST_L1 or DIST_C distance type, the parameter is forced to 3 because a 3×3 mask gives the same result as 5×5 or any larger aperture.
----距离变换蒙版的大小,请参阅 DistanceTransformMasks。 此变体不支持 DIST_MASK_PRECISE。 在 DIST_L1 或 DIST_C 距离类型的情况下,该参数被强制为 3,因为 3×3 掩膜给出与 5×5 或任何更大孔径相同的结果。
labelType Type of the label array to build, see DistanceTransformLabelTypes.
--标签数组的类型
distanceTransform() [2/2]
这是一个重载的成员函数,是为了方便而提供的。 它与上述函数的不同之处仅在于它接受的参数。
c++格式:
void cv::distanceTransform ( InputArray src,
OutputArray dst,
int distanceType,
int maskSize,
int dstType = CV_32F
)
python格式:
cv.distanceTransform( src, distanceType, maskSize[, dst[, dstType]] ) -> dst
cv.distanceTransformWithLabels( src, distanceType, maskSize[, dst[, labels[, labelType]]] ) -> dst, labels
参数:
src 8-bit, single-channel (binary) source image.
dst Output image with calculated distances. It is a 8-bit or 32-bit floating-point, single-channel image of the same size as src .
distanceType Type of distance, see DistanceTypes
maskSize Size of the distance transform mask, see DistanceTransformMasks. In case of the DIST_L1 or DIST_C distance type, the parameter is forced to 3 because a 3×3 mask gives the same result as 5×5 or any larger aperture.
----距离变换蒙版的大小,请参阅 DistanceTransformMasks。 在 DIST_L1 或 DIST_C 距离类型的情况下,该参数被强制为 3,因为 3×3 掩膜给出与 5×5 或任何更大孔径相同的结果。
dstType Type of output image. It can be CV_8U or CV_32F. Type CV_8U can be used only for the first variant of the function and distanceType == DIST_L1.
----输出图像的类型。 它可以是 CV_8U 或 CV_32F。 类型 CV_8U 只能用于函数的第一个变体和 distanceType == DIST_L1。
DistanceTypes
距离变换和 M 估计器的距离类型
DistanceTransformMasks
DIST_MASK_3 Python: cv.DIST_MASK_3 | mask=3 3*3掩膜 |
DIST_MASK_5 Python: cv.DIST_MASK_5 | mask=5 5*5掩膜 |
DIST_MASK_PRECISE Python: cv.DIST_MASK_PRECISE |
@meng