opencv距离变换

xiaoxiao2021-02-28  160

http://blog.sina.com.cn/s/blog_45eaa01a0102wrwp.html

http://www.vlfeat.org/overview/imdisttf.html

http://cn.mathworks.com/help/images/distance-transform.html matlab距离变换

距离变换提供了图像中点分离的度量或度量。的bwdist函数计算每个像素间的距离,设置为OFF(0)和最近的非零像素的二进制图像 

gua'jia

Calculates the distance to the closest zero pixel for each pixel of the source image.

C++:  void  distanceTransform (InputArray  src, OutputArray  dst, int  distanceType, int  maskSize, int  dstType=CV_32F  ) C++:  void  distanceTransform (InputArray  src, OutputArray  dst, OutputArray  labels, int  distanceType, int  maskSize, int labelType=DIST_LABEL_CCOMP  ) Python:   cv2. distanceTransform (src, distanceType, maskSize [, dst ] ) → dst C:  void  cvDistTransform (const CvArr*  src, CvArr*  dst, int  distance_type=CV_DIST_L2, int  mask_size=3, const float* mask=NULL, CvArr*  labels=NULL, int  labelType=CV_DIST_LABEL_CCOMP  ) Parameters: 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 .含计算出的距离的输出图像(32-比特、浮点数、单通道).  distanceType – Type of distance. It can be CV_DIST_L1, CV_DIST_L2 , or CV_DIST_C .距离类型: CV_DIST_L1, CV_DIST_L2, CV_DIST_C 或 CV_DIST_USERmaskSize – Size of the distance transform mask. It can be 3, 5, or CV_DIST_MASK_PRECISE (the latter option is only supported by the first function). In case of the CV_DIST_L1 or CV_DIST_C distance type, the parameter is forced to 3 because a  mask gives the same result as  or any larger aperture.距离变换掩模的大小,可以是 3 或 5. 对 CV_DIST_L1 或 CV_DIST_C 的情况,参数值被强制设定为 3, 因为 3×3 mask 给出 5×5 mask 一样的结果,而且速度还更快。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 == CV_DIST_L1.labels – Optional output 2D array of labels (the discrete Voronoi diagram). It has the type CV_32SC1and the same size as src . See the details below.labelType – Type of the label array to build. If labelType==DIST_LABEL_CCOMP then each connected component of zeros in src (as well as all the non-zero pixels closest to the connected component) will be assigned the same label. If labelType==DIST_LABEL_PIXEL then each zero pixel (and all the non-zero pixels closest to it) gets its own label.

The functions distanceTransform calculate the approximate or precise distance from every binary image pixel to the nearest zero pixel. For zero image pixels, the distance will obviously be zero.

When maskSize == CV_DIST_MASK_PRECISE and distanceType == CV_DIST_L2 , the function runs the algorithm described in [Felzenszwalb04]. This algorithm is parallelized with the TBB library.

In other cases, the algorithm [Borgefors86] is used. This means that for a pixel the function finds the shortest path to the nearest zero pixel consisting of basic shifts: horizontal, vertical, diagonal, or knight’s move (the latest is available for a  mask). The overall distance is calculated as a sum of these basic distances. Since the distance function should be symmetric, all of the horizontal and vertical shifts must have the same cost (denoted as a ), all the diagonal shifts must have the same cost (denoted as b ), and all knight’s moves must have the same cost (denoted as c ). For the CV_DIST_Cand CV_DIST_L1 types, the distance is calculated precisely, whereas for CV_DIST_L2 (Euclidean distance) the distance can be calculated only with a relative error (a  mask gives more accurate results). For a,``b`` , and c , OpenCV uses the values suggested in the original paper:

CV_DIST_C a = 1, b = 1 CV_DIST_L1 a = 1, b = 2 CV_DIST_L2 a=0.955, b=1.3693 CV_DIST_L2 a=1, b=1.4, c=2.1969

Typically, for a fast, coarse distance estimation CV_DIST_L2, a  mask is used. For a more accurate distance estimation CV_DIST_L2 , a  mask or the precise algorithm is used. Note that both the precise and the approximate algorithms are linear on the number of pixels.

The second variant of the function does not only compute the minimum distance for each pixel  but also identifies the nearest connected component consisting of zero pixels (labelType==DIST_LABEL_CCOMP) or the nearest zero pixel (labelType==DIST_LABEL_PIXEL). Index of the component/pixel is stored in  . WhenlabelType==DIST_LABEL_CCOMP, the function automatically finds connected components of zero pixels in the input image and marks them with distinct labels. When labelType==DIST_LABEL_CCOMP, the function scans through the input image and marks all the zero pixels with distinct labels.

In this mode, the complexity is still linear. That is, the function provides a very fast way to compute the Voronoi diagram for a binary image. Currently, the second variant can use only the approximate distance transform algorithm, i.e.maskSize=CV_DIST_MASK_PRECISE is not supported yet.

Image Matching Using Distance Transform

Improved Chamfer Matching Using Interpolated Chamfer Distance and Subpixel Search 

Template matching using distance transform

二值图像的距离变换研究

Hierarchical Chamfer Matching: A Parametric Edge Matching Algorithm 

Modified Chamfer Matching Algorithm

转载请注明原文地址: https://www.6miu.com/read-21339.html

最新回复(0)