图形学

[Computer Vision]距离变换与OTSU二值化

2022-08-14  本文已影响0人  _小老虎_

1 距离变换

以Opencv的distanceTransform距离变换为例。

1.1 梗概

计算图像中每一个非零点距离离自己最近零点的距离,distanceTransform的第二个Mat矩阵参数dst保存了每一个点与最近的零点的距离信息,图像上越亮的点,代表了离零点的距离越远

1.2 详解

1.2.1 变换

Distance fields can also be signed, in the case where it is important to distinguish whether the point is inside or outside of the shape.[1]
Usually the transform/map is qualified with the chosen metric. For example, one may speak of Manhattan distance transform, if the underlying metric is Manhattan distance

1.2.1.1 下图为欧式距离和曼哈顿距离的区别
image.png
1.2.1.2 距离变换 (曼哈顿距离(Manhattan distance)标准讲解)

以二值图像为例,计算0到非0的距离;其中区域块内部的像素值为1,其他像素值为0。距离变换给出每个像素点到最近的区域块边界的距离,区域块内部的距离变换结果为0。输入图像如图1所示,D4距离的距离变换结果如图2所示。

image
image.png
image

具体的距离变换的距离计算可以多种多样,只是不同方法性能不一。
常用『掩模』

1.2.2 举例

变换前(二值化/开运算)


before distance transform

变换后


distanceTransform

1.3 用途

1.3.1 watershed 分水岭算法 ( 细化轮廓 )
image.png
image.png
image.png
image.png
cv2.connectedComponents
# 去重后的标记区域的点
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 34, 36, 32, 33, 35, 37]
连通标记之后 plt.show.png
1.3.2 细化轮廓和查找物体质心
image.png
image.png

1.4 其他

1.5 参考文献

2 OTSU二值化算法 (类间方差)

是日本学者大津(OTSU)提出来的

2.1 梗概

大津法(OTSU)是一种确定图像二值化分割阈值的算法,由日本学者大津于1979年提出

2.2 详解

2.2.1 算法过程
说白了就是一张图下, [0,t) , [t,255] 分别代表前景,后景的两个区间分两类,
然后分别求对于质量矩的方差所决定的最佳阈值。
(其中还有`前景总点数(权重)`和后景的乘积有关系)
2.2.2 过程图示
image.png
image.png

2.3 使用

2.3.1 二值化图像
image.png
image.png

2.4 其他

2.5 参考文献

上一篇 下一篇

猜你喜欢

热点阅读