cvDistTransform距离变换






  1. /*F///
  2. //    Name:     cvDistTransform
  3. //    Purpose:  calculates distance transform of binary image 
  4. //    Context:
  5. //    Parameters:
  6. //      src - source binary image
  7. //      dst - output floating-point image, whose pixel values are distances from
  8. //            the correspondend pixel in the source image to the nearest 0-pixel.
  9. //      disType - type of metric used
  10. //      maskType - size of discrete aperture that approximates the metric.
  11. //      mask - array of 2 (for 3x3 mask) or 3 numbers (for 5x5 mask) that characterizes
  12. //             metric if disType is CV_DIST_USER (user-defined metric)
  13. //    Notes:
  14. //F*/
  15. OPENCVAPI  void  cvDistTransform( IplImage* src, IplImage* dst, CvDisType disType,
  16.                                CvDisMaskType maskType, float* mask CV_DEFAULT(0));


================================================================================




DistTransform

计算输入图像的所有非零元素对其最近零元素的距离

void cvDistTransform( const CvArr* src, CvArr* dst, int distance_type=CV_DIST_L2,

                      int mask_size=3, const float* mask=NULL );

src

输入 8-比特、单通道 (二值) 图像.

dst

含计算出的距离的输出图像(32-比特、浮点数、单通道).

distance_type

距离类型; 可以是 CV_DIST_L1, CV_DIST_L2, CV_DIST_C 或 CV_DIST_USER.

mask_size

距离变换掩模的大小,可以是 3 或 5. 对 CV_DIST_L1 或 CV_DIST_C 的情况,参数值被强制设定为 3, 因为 3×3 mask 给出 5×5 mask 一样的结果,而且速度还更快。

mask

用户自定义距离情况下的 mask。 在 3×3 mask 下它由两个数(水平/垂直位量,对角线位移量)组成, 5×5 mask 下由三个数组成(水平/垂直位移量,对角位移和 国际象棋里的马步(马走日))

函数 cvDistTransform 二值图像每一个象素点到它最邻近零象素点的距离。对零象素,函数设置 0 距离,对其它象素,它寻找由基本位移(水平、垂直、对角线或knight's move,最后一项对 5×5 mask 有用)构成的最短路径。 全部的距离被认为是基本距离的和。由于距离函数是对称的,所有水平和垂直位移具有同样的代价 (表示为 a ), 所有的对角位移具有同样的代价 (表示为 b), 所有的 knight's 移动具有同样的代价 (表示为 c). 对类型 CV_DIST_C 和 CV_DIST_L1,距离的计算是精确的,而类型 CV_DIST_L2 (欧式距离) 距离的计算有某些相对误差 (5×5 mask 给出更精确的结果), OpenCV 使用 [Borgefors86] 推荐的值:

CV_DIST_C (3×3):

a=1, b=1

CV_DIST_L1 (3×3):

a=1, b=2

CV_DIST_L2 (3×3):

a=0.955, b=1.3693

CV_DIST_L2 (5×5):

a=1, b=1.4, c=2.1969

下面用户自定义距离的的距离域示例 (黑点 (0) 在白色方块中间): 用户自定义 3×3 mask (a=1, b=1.5)

4.5

4

3.5

3

3.5

4

4.5

4

3

2.5

2

2.5

3

4

3.5

2.5

1.5

1

1.5

2.5

3.5

3

2

1

0

1

2

3

3.5

2.5

1.5

1

1.5

2.5

3.5

4

3

2.5

2

2.5

3

4

4.5

4

3.5

3

3.5

4

4.5

用户自定义 5×5 mask (a=1, b=1.5, c=2)

4.5

3.5

3

3

3

3.5

4.5

3.5

3

2

2

2

3

3.5

3

2

1.5

1

1.5

2

3

3

2

1

0

1

2

3

3

2

1.5

1

1.5

2

3

3.5

3

2

2

2

3

3.5

4

3.5

3

3

3

3.5

4

典型的使用快速粗略距离估计 CV_DIST_L2, 3×3 mask , 如果要更精确的距离估计,使用 CV_DIST_L2, 5×5 mask。

When the output parameter labels is not NULL, for every non-zero pixel the function also finds the nearest connected component consisting of zero pixels. The connected components themselves are found as contours in the beginning of the function.

In this mode the processing time is still O(N), where N is the number of pixels. Thus, the function provides a very fast way to compute approximate Voronoi diagram for the binary image.

  1. /*F///
  2. //    Name:     cvDistTransform
  3. //    Purpose:  calculates distance transform of binary image 
  4. //    Context:
  5. //    Parameters:
  6. //      src - source binary image
  7. //      dst - output floating-point image, whose pixel values are distances from
  8. //            the correspondend pixel in the source image to the nearest 0-pixel.
  9. //      disType - type of metric used
  10. //      maskType - size of discrete aperture that approximates the metric.
  11. //      mask - array of 2 (for 3x3 mask) or 3 numbers (for 5x5 mask) that characterizes
  12. //             metric if disType is CV_DIST_USER (user-defined metric)
  13. //    Notes:
  14. //F*/
  15. OPENCVAPI  void  cvDistTransform( IplImage* src, IplImage* dst, CvDisType disType,
  16.                                CvDisMaskType maskType, float* mask CV_DEFAULT(0));
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值