基于distanceTransform-距离变换的区域中心提取

合集下载

基于边界距离场的管腔中心路径自动提取算法

基于边界距离场的管腔中心路径自动提取算法

取 中心 路 径 . 验 结 果 表 明 , 确 的边 界距 离 场 使 得 提 取 的 中心 路 径 更 加 精 确 , 快 速 算 法 的 应 用 提 高 了 该 算 法 的 实 精 而
效 率 , 得 的结 果 可 直 接用 作 虚 拟 内 窥 镜 的 漫 游 路 径 . 获
关键 词 虚 拟 内窥 镜 ; 界 距 离 场 ; 边 中心 路 径 提 取
0 引

得类似 的观 察效 果 , 虚拟 内窥 镜 漫 游数 字 器官 的 在
过程 中 , 虚拟 相机最 好也 能 够沿 着一 定 的路径 行 走 .
虚拟 内 窥 镜 技 术 随 着 高 分 辨 医 学 图 像 ( T, C MRI ) 出现 , 等 的 以及 虚 拟 现 实技 术 的 不 断 完 善 和 提高, 已得 到迅 速发展 , 同时也 成 为虚 拟现 实技 术走
ag rt m h e trieo h u ua be t se tatdfo t eMS te . ee p r n a eut h w lo ih t ec n el ft et b lr jc x r ce rm h T re Th x e i t l s l s o n o i me r s
统 中的关 键技 术之 一. 实现 漫游 路径 的 自动 规划一 般 可分 为拓 扑逻辑
细化 法 和距离 变换 法 2种 . 扑 逻 辑细 化 法 通过 反 拓 复剥 除物 体 的最 外层 体 素 , 到 只剩 下 一 个 体 素作 直 为该 物体 的 骨 架 . 然 这 种 算 法 的 思 想 非 常 简 单 , 虽 但是其 计 算 量 非 常 大 _ , 使 是 其 快 速 算 法 _ , 2 即 J 3 也 ]
J n ,2 0 ue 06

基于距离变换与路径规划的骨架提取算法

基于距离变换与路径规划的骨架提取算法
s∈ S
那么 p1 就是局部距离变换 最 大 值 点,所 有 最 大 值点的集合为 Lmax。图 5是根 据 图 3得 出 的 距 离 变 换局部最大值的图像。
定义 2:距离 变 换 梯 度 的 模 同 样 反 应 骨 架 点 的 情况。假 设 p2 象 素 的 距 离 变 换 梯 度 的 模 的 值 为 ‖f(p2)‖,p2 的 8邻 域 象 素 点 为 集 合 S,如 果 满 足以下条件:
基于骨架提取 的 重 要 性,在 文 献 中 提 出 了 大 量 的骨架提取算法。这些骨架提取算法大致可以分为 四 类 [3]:① 中 轴 变 换 (medicalaxistransform)[4-5]; ② 细化算 法 (thinningalgorithm)[6-8];③ 距 离 变 换 (distancetransform)[9-12];④ 路 径 规 划 算 法 (path planningalgorithm)[9,13-14]。
中轴在数学术语中可以用最大内切圆的相关术 语定义,一个对称点 是 两 个 或 多 个 有 着 相 等 长 度 的 圆盘法线的交点。其中圆盘法线是从对称点到边界 的最短长度的线段。由于一个目标内点的最大内切 圆在边界上至少有 两 个 切 点,所 以 每 个 对 称 点 有 两 个或多个圆盘法线。中轴变换实现起来较为困难, 中轴变换用于识别 的 最 大 缺 点 就 是:边 界 上 的 很 小 变化会使得对称轴人为产生冗余的长分支。细化算 法的基本思想是通过利用分层单向或双向迭代的方 法更改目标边缘的 点 为 背 景 点,直 到 目 标 变 成 了 一 些单象素宽的曲线所构成的结合。尽管细化算法可 以很好地保留物体 的 拓 扑 形 状,但 是 生 成 的 骨 架 依 赖于初始条件,且 迭 代 过 程 耗 时 较 大。 文 献 讨 [8] 论 了接近 300种细 化 算 法,近 年 来 也 提 出 了 许 多 新 的 细化算法,如势 能 场、水 平 集、主 曲 线 评 价 法 等。 传 统的距离变换算法通过在高一维空间中生成的距离 曲面形成的脊线来建立骨架。它们的主要特点是骨 架 位 置 准 确 ,外 形 顺 滑 ,缺 点 在 于 容 易 受 到 边 缘 噪 声 的干扰且难以保证骨架的准确性。而路径规划算法 通过寻找两点间的 最 短 路 径,通 过 定 义 骨 架 的 起 始 点与终止点,两点 间 的 最 短 路 径 即 是 骨 架。 路 径 规 划算法可以将物体的拓扑性与连续性很好地保留。

基于distanceTransform-距离变换的区域中心提取

基于distanceTransform-距离变换的区域中心提取

基于distanceTransform-距离变换的区域中⼼提取这⼏天在做⼀个⼿势识别的项⽬,其中最的关键⼀步是提取⼿掌中⼼。

获得⼿掌重⼼通常的做法是计算整个⼿部的重⼼,并以该重⼼位置近似⼿掌重⼼,这种⽅法只适⽤于没有⼿指伸出或只有⼀个⼿指伸出的情况,否则获得的⼿掌重⼼位置将严重偏离真实位置。

距离变换的基本含义是计算⼀个图像中⾮零像素点到最近的零像素点的距离,也就是到零像素点的最短距离。

因此可以基于距离变换提取⼿掌重⼼。

算法基本思想:(1)将⼿掌图像⼆值化,⼿掌内的区域设为⽩⾊,外部区域设为⿊⾊。

(2)将⼆值化后的图像经过distanceTransform变换,得到dist_image,其中每个像素点的值是该像素点到其最近的零像素点的距离。

(3)找到dist_image的最⼤值(即圆的半径R),并记录下位置(即圆⼼坐标)。

代码如下:[cpp]view plaincopy1. #include "opencv2/opencv.hpp"2. #include <opencv2/core/core.hpp>3. #include <opencv2/highgui/highgui.hpp>4. #include <opencv2/imgproc/imgproc.hpp>5. #include <vector>6. using namespace cv;7. using namespace std;8.9. pair<Point,double> DetectInCircles(vector<Point> contour,Mat src)10. {11.12. Mat dist_image;13. distanceTransform(src,dist_image,CV_DIST_L2,3);14. int temp=0,R=0,cx=0,cy=0;15. int d;16. for (int i=0;i<src.rows;i++)17. for (int j=0;j<src.cols;j++)18. {19. /* checks if the point is inside the contour. Optionally computes the signed distance from the point to the contour boundary*/20. d = pointPolygonTest(contour, Point2f(j, i), 0);21. if (d>0)22. {23. temp=(int)dist_image.ptr<float>(i)[j];24. if (temp>R)25. {26. R=temp;27. cy=i;28. cx=j;29. }30.31. }32. }33.34.35. return make_pair(Point(cx,cy),R);36.37. }38.39. int main()40. {41. // Read input binary image41. // Read input binary image42. Mat src= imread("D:\\mycode\\6.jpg",1);43. Mat image;44. cvtColor(src,image,CV_BGR2GRAY);45. vector<vector<Point>> contours;46.47. //findContours的输⼊是⼆值图像48. findContours(image,49. contours, // a vector of contours50. CV_RETR_EXTERNAL, // retrieve the external contours51. CV_CHAIN_APPROX_NONE); // retrieve all pixels of each contours52.53. // Print contours' length轮廓的个数54. cout << "Contours: " << contours.size() << endl;55. vector<vector<Point>>::const_iterator itContours= contours.begin();56. for ( ; itContours!=contours.end(); ++itContours) {57.58. cout << "Size: " << itContours->size() << endl;//每个轮廓包含的点数59. }60. //找到最⼤轮廓61. int index=0,maxArea=0;62. for(unsigned int i=0;i<contours.size();i++)63. {64. int area=contourArea(contours[i]);65. if (area>maxArea)66. {67. index=i;68. maxArea=area;69. }70. }71. // draw black contours on white image72. Mat result(image.size(),CV_8U,Scalar(0));73. drawContours(result,contours, //画出轮廓74. -1, // draw all contours75. Scalar(255), // in black76. 2); // with a thickness of 277.78.79. pair<Point,double> m=DetectInCircles(contours[index],image);80.81. cout<<m.first.x<<" "<<m.first.y<<" "<<m.second<<endl;82. circle(src,m.first,3,Scalar(0,0,255),2);83. circle(src,m.first,m.second,Scalar(0,0,255),1);84. namedWindow("result");85. imshow("result",src);86. waitKey(0);87.88. return 0;89. }结果:原图 dist_image 结果其中有⼀点需要注意:[cpp]view plaincopy1. distanceTransform(InputArray src, OutputArray dst, int distanceType, int maskSize)2.3. Parameters:4. src – 8-bit, single-channel (binary) source image.5. dst – Output image with calculated distances. It is a 32-bit floating-point, single-channel6. image of the same size as src .7. distanceType – Type of distance. It can be CV_DIST_L1, CV_DIST_L2 , or CV_DIST_C .8. maskSize – Size of the distance transform mask. It can be 3, 5, or CV_DIST_MASK_PRECISE9. (the latter option is only supported by the first function). In case of the CV_DIST_L1 or10. CV_DIST_C distance type, the parameter is forced to 3 because a 3 3 mask gives the same11. result as 5 5 or any larger aperture.12. labels – Optional output 2D array of labels (the discrete Voronoi diagram). It has the type13. CV_32SC1 and the same size as src . See the details below.dst为单通道的32-bit 浮点型矩阵,读取元素时需要⽤image.ptr<float>(i)[j],⽤imshow显⽰的时候需要⽤normalize(dist_image, magI, 0, 1, CV_MINMAX); 将float类型的矩阵转换到可显⽰图像范围 (float [0, 1]).。

opencv实现机器视觉检测和计数的方法

opencv实现机器视觉检测和计数的方法

opencv实现机器视觉检测和计数的⽅法引⾔在机器视觉中,有时需要对产品进⾏检测和计数。

其难点⽆⾮是对于产品的图像分割。

由于之前⽹购的维⽣素⽚,有时候忘了今天有没有吃过,就想对瓶⼦⾥的药⽚计数...在学习opencv以后,希望实现对于维⽣素⽚分割计数算法。

本次实战在基于形态学的基础上⼜衍⽣出基于距离变换的分⽔岭算法,使其实现的效果更具普遍性。

基于形态学的维⽣素⽚检测和计数整体思路:读取图⽚形态学处理(在⼆值化前进⾏适度形态学处理,效果俱佳)⼆值化提取轮廓(进⾏药⽚分割)获取轮廓索引,并筛选所需要的轮廓画出轮廓,显⽰计数opencv实现:int main(int argc, char** argv){Mat src, src_binary,dst,src_distance;src = imread("D:/opencv练习图⽚/维⽣素⽚机器视觉检测和计数.png");imshow("原图⽚", src);Mat kernel = getStructuringElement(MORPH_RECT, Size(16, 16), Point(-1, -1));morphologyEx(src, dst, MORPH_OPEN, kernel);imshow("形态学",dst);cvtColor(dst, dst, COLOR_RGB2GRAY);threshold(dst, src_binary, 100, 255, THRESH_OTSU);imshow("⼆值化", src_binary);vector<vector<Point>> contours;findContours(src_binary, contours, RETR_EXTERNAL, CHAIN_APPROX_NONE, Point(0, 0));RNG rng(12345);double area;Point2i PL;for (size_t i = 0; i < contours.size(); i++){area = contourArea(contours[i]);if (area < 500)continue;PL = contours[i].front();Scalar color = Scalar(rng.uniform(0, 255), rng.uniform(0, 255), rng.uniform(0, 255));drawContours(src, contours, i, color, 2, 8);putText(src, to_string(i), PL, FONT_HERSHEY_COMPLEX, 1, color, 2);}imshow("计数结果", src);waitKey(0);return 0;}效果展⽰:由上图可以看的,原图在经过形态学处理后,可以去除很多细节,简化后续的药⽚分割操作。

基于TensorFlow的掌纹识别方法研究

基于TensorFlow的掌纹识别方法研究

基于TensorFlow的掌纹识别方法研究作者:王全来源:《价值工程》2018年第33期摘要:使用掌纹作为生物特征进行身份认证是近年来一门兴起的技术,本文提出一种基于TensorFlow的掌纹识别方法。

该方法首先应用TensorFlow Object Detection API使用Google ML Engine云计算技术对获取到的手掌图像进行训练,利用得到的模型在本地完成手掌检测;然后通过手掌检测获得的ROI,使用OpenCV得部分掌纹;最后采用TensorFlow自行编写的卷积神经网络,对提取到的掌纹图像进行训练,得到训练模型进行分类预测。

实验表明,该方法对比PCA、LBP等算法、得到了较高的识别率。

Abstract: Using palmprint as biometrics for identity authentication is a rising technology in recent years. This paper proposes a palmprint recognition method based on TensorFlow. The method first uses the TensorFlow Object Detection API to train the acquired palm image using Google ML Engine cloud computing technology. The palm can be detected locally by using the model. And then the ROI obtained by palm detection. Use OpenCV to get partial palmprint. Finally, the convolutional neural network constructed by TensorFlow is used. The extracted palmprint image is trained to obtain a training model for classification prediction. Experiments show that this method,compared with PCA, LBP and other algorithms, obtains a higher recognition rate.关键词:掌纹识别;卷积神经网络;手掌检测;掌纹提取Key words: palmprint recognition;convolutional neural networks;palm detection;palmprint extraction中图分类号:TP391 文献标识码:A 文章编号:1006-4311(2018)33-0169-030 引言掌纹识别是一种新颖的生物识别技术。

图像处理距离变换算法

图像处理距离变换算法

图像处理距离变换算法距离定义满⾜以下函数条件D(p,q)>=0,当且仅当p=q时D(p,q)=0;D(p,q)=D(q,p)D(p,r)<=D(p,q)+D(q,r)欧式距离D[(i,j),(k,h)]=((i-k)^2+(j-h)^2)^(1/2);城市街区距离只允许横向以及纵向的移动D[(i,j),(k,h)]=|i-k|+|j-h|;棋盘距离允许横向、纵向以及对⾓线上的移动D[(i,j),(k,h)]=max{|i-k|,|j-h|}算法实现步骤1.按照⼀种距离度量D,D是D4或D8,对⼤⼩为M*N的图像的⼀个⼦集S计算距离变换,建⽴⼀个M*N的数组F并作初始化:⼦集S中元素置为0,其他置为⽆穷。

2.按⾏遍历图像,从上到下,从左到右。

对于上⽅和左⾯的邻接像素设F(p)=min[F(p),D(p,q)+F(q)]。

3.按⾏遍历图像,从下到上,从右到左。

对于下⽅和右⾯的邻接像素设F(p)=min[F(p),D(p,q)+F(q)]。

4.数组F中得到的是⼦集S的斜切。

具体函数初始化函数void DistanceTransformD4(vector<vector<int>> &src, vector<vector<int>> &f){int cols = src[0].size();int rows = src.size();//初始化for (int i = 0; i < rows; ++i)for (int j = 0; j < cols; ++j)if (src[i][j] == 1)f[i][j] = 0;elsef[i][j] = INT_MAX - 2;//简单的防⽌溢出//按⾏遍历图像,从上到下,从左到右for (int i = 0; i < rows; ++i)for (int j = 0; j < cols; ++j)D4AL(i, j, rows, cols, f);//按⾏遍历图像,从下到上,从右到左for (int i = rows - 1; i >= 0; --i)for (int j = cols - 1; j >= 0; --j)D4BR(i, j, rows, cols, f);}左变换函数void D4AL(int i,int j, int rows, int cols, vector<vector<int>> &f){//上if (InArea(i - 1, j, rows, cols))f[i][j] = min(f[i][j], 1 + f[i - 1][j]);//左上if (InArea(i - 1, j - 1, rows, cols))f[i][j] = min(f[i][j], 2 + f[i - 1][j - 1]);//左if (InArea(i, j - 1, rows, cols))f[i][j] = min(f[i][j], 1 + f[i][j - 1]);//左下if (InArea(i + 1, j - 1, rows, cols))f[i][j] = min(f[i][j], 2 + f[i + 1][j - 1]);}右变换函数void D4BR(int i, int j, int rows, int cols, vector<vector<int>> &f) {//下if (InArea(i + 1, j, rows, cols))f[i][j] = min(f[i][j], 1 + f[i + 1][j]);//右下if (InArea(i + 1, j + 1, rows, cols))f[i][j] = min(f[i][j], 2 + f[i + 1][j + 1]);//右if (InArea(i, j + 1, rows, cols))f[i][j] = min(f[i][j], 1 + f[i][j + 1]);//右上if (InArea(i - 1, j + 1, rows, cols))f[i][j] = min(f[i][j], 2 + f[i - 1][j + 1]);}判断是否出界函数bool InArea(int i, int j, int rows, int cols){if (i<0 || i>=rows)return false;if (j<0 || j>=cols)return false;return true;}。

distancetransform用法

distancetransform用法

distancetransform用法distancetransform是一种图像处理算法,它可以计算每个像素点到离它最近的像素点的距离。

这个算法在很多应用中都有广泛的应用,比如目标检测、图像分割、形态学操作等等。

本文将介绍distancetransform的用法,并给出实例说明。

distancetransform 的基本原理是在输入图像中寻找相邻像素点之间的最短距离的过程。

算法的核心思想有两个关键点:- 首先,需要定义一个距离函数。

常用的距离函数有欧几里得距离(常用于灰度图像)和曼哈顿距离(常用于二值图像)等等,本文采用欧几里得距离。

- 其次,需要前向和后向一次扫描来确保每个像素点到离它最近的像素距离被计算。

这个算法的基本流程如下:- 首先,对输入图像进行阈值处理,将其二值化。

- 然后,对二值图像进行距离变换。

- 最后,对距离转换的结果进行处理,可进行形态学操作。

dst=cv2.distanceTransform(src, distType, maskSize)其中,src表示输入图像,distType表示距离转换类型,maskSize表示距离转换的卷积核大小。

- distType - 它指定距离变换的类型。

常用的类型有:- cv2.DIST_L1:曼哈顿距离- cv2.DIST_L2:欧几里得距离- cv2.DIST_C:切比雪夫距离- maskSize - 指定距离转换的卷积核大小。

常用的值为3或5。

dst是距离转换结果的输出数组。

3. 实例分析首先,我们需要准备一张图像。

在这个简单的示例中,我们使用一张长度和宽度都为200像素的灰度图像。

下面是我们将要使用的代码:import cv2import numpy as npfrom matplotlib import pyplot as pltimage = cv2.imread('image.jpg',0)plt.imshow(image,cmap='gray')plt.show()然后,我们需要将灰度图像二值化。

distancetransform函数

distancetransform函数

Distancetransform函数介绍在计算机视觉和图像处理领域中,distancetransform函数是一种常用的图像处理工具。

它用来计算二值图像中每个像素点到最近边界的距离。

这个函数的核心思想是根据像素点的位置来计算其与最近边界的距离,从而为图像提供更丰富的信息。

背景在许多图像处理的应用中,我们需要了解图像中各个像素点与图像边界的距离。

例如,在边缘检测算法中,我们常常需要知道每个像素点到最近边界的距离,以便进一步分析图像的边缘结构。

而在路径规划算法中,我们需要计算每个像素点到障碍物边界的距离,以便寻找到最短路径。

在这些应用中,distancetransform函数起到了关键的作用。

distancetransform函数的原理distancetransform函数的核心原理是计算每个像素点到最近边界的距离。

其主要思想可以归纳为以下几步:1.首先,需要将输入的二值图像进行一定的预处理操作。

例如,可能需要对图像进行二值化处理,将图像中的灰度值转换为二值(0和1)。

2.然后,根据二值图像中的像素点信息,计算每个像素点到最近边界的距离。

这个过程可以使用多种算法来实现,常见的有腐蚀操作、曼哈顿距离、欧氏距离等。

3.最后,将计算得到的距离信息存储在一个新的图像中,并返回该图像作为函数的输出结果。

distancetransform函数的算法实现distancetransform函数的实现可以使用多种算法。

以下是常见的一些算法:1. 腐蚀操作腐蚀操作是一种简单且有效的计算距离的方法。

它的基本思想是遍历图像中的每个像素点,对于每个像素点,计算它到最近边界的距离。

具体步骤如下:1.初始化一个与输入图像相同大小的距离图像,并将其中的元素值设置为一个较大的值(例如,无穷大)。

2.从左上角开始遍历图像中的每个像素点,对于每个像素点,计算它到最近边界的距离。

3.对于每个像素点,将其与邻域像素点的距离进行比较,取最小值作为该像素点的距离值。

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

基于distanceTransform-距离变换的区域中心提取
这几天在做一个手势识别的项目,其中最的关键一步是提取手掌中心。

获得手掌重心通常的做法是计算整个手部的重心,并以该重心位置近似手掌重心,这种方法只适用于没有手指伸出或只有一个手指伸出的情况,否则获得的手掌重心位置将严重偏离真实位置。

距离变换的基本含义是计算一个图像中非零像素点到最近的零像素点的距离,也就是到零像素点的最短距离。

因此可以基于距离变换提取手掌重心。

算法基本思想:
(1)将手掌图像二值化,手掌内的区域设为白色,外部区域设为黑色。

(2)将二值化后的图像经过distanceTransform变换,得到dist_image,其中每个像素点的值是该像素点到其最近的零像素点的距离。

(3)找到dist_image的最大值(即圆的半径R),并记录下位置(即圆心坐标)。

代码如下:
[cpp] view plaincopy#include "opencv2/opencv.hpp"
#include &lt;opencv2/core/core.hpp&gt; #include
&lt;opencv2/highgui/highgui.hpp&gt; #include
&lt;opencv2/imgproc/imgproc.hpp&gt; #include
&lt;vector&gt; using namespace cv; using namespace std; pair&lt;Point,double&gt; DetectInCircles(vector&lt;Point&gt; contour,Mat src)
{ Mat dist_image;
distanceTransform(src,dist_image,CV_DIST_L2,3);
int temp=0,R=0,cx=0,cy=0; int d; for (int
i=0;i&lt;src.rows;i++) for (int j=0;j&lt;src.cols;j++) { /* checks if the point is inside the contour. Optionally computes the signed distance from the point to the contour boundary*/ d = pointPolygonTest(contour, Point2f(j, i), 0); if (d&gt;0)
{ temp=(int)dist_image.ptr&lt;float&gt;(i )[j]; if (temp&gt;R)
{ R=temp;
cy=i;
cx=j; }
} }
return make_pair(Point(cx,cy),R); } int main() { // Read input binary image
Mat src= imread("D:\\mycode\\6.jpg",1); Mat image; cvtColor(src,image,CV_BGR2GRAY);
vector&lt;vector&lt;Point&gt;&gt; contours;
//findContours的输入是二值图像
findContours(image, contours, // a vector of contours CV_RETR_EXTERNAL, // retrieve the external contours
CV_CHAIN_APPROX_NONE); // retrieve all pixels of each contours // Print contours' length轮廓的个数cout &lt;&lt; "Contours: " &lt;&lt; contours.size() &lt;&lt; endl; vector&lt;vector&lt;Point&gt;&gt;::const_iterator
itContours= contours.begin(); for ( ;
itContours!=contours.end(); ++itContours)
{ cout &lt;&lt; "Size: " &lt;&lt;
itContours-&gt;size() &lt;&lt; endl;//每个轮廓包含的点
数} //找到最大轮廓int
index=0,maxArea=0; for(unsigned int
i=0;i&lt;contours.size();i++) { int
area=contourArea(contours[i]); if
(area&gt;maxArea) { index=i; maxArea=area; } } // draw black contours on white image Mat
result(image.size(),CV_8U,Scalar(0));
drawContours(result,contours, //画出轮廓
-1, // draw all contours Scalar(255), // in black 2); // with a thickness of 2
pair&lt;Point,double&gt;
m=DetectInCircles(contours[index],image);
cout&lt;&lt;m.first.x&lt;&lt;" "&lt;&lt;m.first.y&lt;&lt;"
"&lt;&lt;m.second&lt;&lt;endl;
circle(src,m.first,3,Scalar(0,0,255),2);
circle(src,m.first,m.second,Scalar(0,0,255),1); namedWindow("result"); imshow("result",src); waitKey(0); return 0; } 结果:
原图dist_image 结果
其中有一点需要注意:
[cpp] view plaincopydistanceTransform(InputArray src, OutputArray dst, int distanceType, int maskSize)
Parameters:src – 8-bit, single-channel (binary) source image. dst – Output image with calculated distances. It is a 32-bit floating-point, single-channel image of the same size as src . distanceType – Type of distance. It can be CV_DIST_L1, CV_DIST_L2 , or CV_DIST_C . maskSize – 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 3 3 mask gives the same result as 5 5 or any larger aperture. labels – Optional output 2D array of labels (the discrete Voronoi diagram). It has the type
CV_32SC1 and the same size as src . See the details below. dst为单通道的32-bit 浮点型矩阵,读取元素时需要用image.ptr&lt;float&gt;(i)[j],用imshow显示的时候需要用normalize(dist_image, magI, 0, 1, CV_MINMAX); 将float类型的矩阵转换到可显示图像范围(float [0, 1]).
另外还有一个博客值得参考:
/wuhaibing_cver/article/details/8602461。

相关文档
最新文档