让我们应用dilation。该操作可以连续应用,因此可以指定数个iterations。既然你想要一个有点强的效果,让我们试试10 iterations。该操作需要第二个名为“structural Element”(SE)的操作数,该操作数选择形状定义子区域中的像素。有不同种类的SE。最常见的一种是3 x 3{}:
# Set morph operation iterations:
opIterations = 10
# Set Structuring Element size:
structuringElementSize = (3, 3)
# Set Structuring element shape:
structuringElementShape = cv2.MORPH_RECT
# Get the Structuring Element:
structuringElement = cv2.getStructuringElement(structuringElementShape, structuringElementSize)
# Perform Dilate:
dilateImg = cv2.morphologyEx(binaryImage, cv2.MORPH_DILATE, structuringElement, None, None, opIterations, cv2.BORDER_REFLECT101)
# Show the image:
cv2.imshow("dilateImg", dilateImg)
cv2.waitKey(0)
您描述的内容可以通过
morphology
实现。形态学操作是一组影响图像整体形状的(逻辑)操作。它可以“扩展”或“减少”形状区域,以及许多其他cool operations让我们使用膨胀来扩展图像的形状:
第一位将您发布的图像转换为二值图像,因为形态学操作只能在单通道图像(也是灰度图像)上执行,但由于我们将应用基本膨胀,二值图像就足够了。这是上述代码片段的结果:
让我们应用}:
dilation
。该操作可以连续应用,因此可以指定数个iterations
。既然你想要一个有点强的效果,让我们试试10 iterations
。该操作需要第二个名为“structural Element”(SE
)的操作数,该操作数选择形状定义子区域中的像素。有不同种类的SE
。最常见的一种是3 x 3
{结果是:
相关问题 更多 >
编程相关推荐