【发布时间】:2019-10-19 21:59:11
【问题描述】:
【问题讨论】:
标签: python-3.x matlab image-processing image-segmentation edge-detection
【问题讨论】:
标签: python-3.x matlab image-processing image-segmentation edge-detection
由于您的标签表明您也对 Python 解决方案持开放态度,因此我提出了使用 OpenCV 的以下方法,特别是 cv2.HoughCircles 方法,遵循 this tutorial。
代码如下:
import cv2
import numpy as np
# Read input image
img = cv2.imread('images/xbHB0.jpg', cv2.IMREAD_GRAYSCALE)
# Blur input image to prevent too much false-positive detected circles
img = cv2.GaussianBlur(img, (3, 3), 0)
# Initialize outputs
clean = np.zeros(img.shape, np.uint8)
compare = cv2.cvtColor(img, cv2.COLOR_GRAY2BGR)
# Detect circles using Hough transform; convert center points and radii to int
circles = cv2.HoughCircles(img, cv2.HOUGH_GRADIENT, 1, 20, param1=50, param2=25, minRadius=10, maxRadius=0)
circles = np.uint16(np.around(circles))
# Draw detected circle to outputs
for i in circles[0, :]:
cv2.circle(clean, (i[0], i[1]), i[2], 255, 1)
cv2.circle(compare, (i[0], i[1]), i[2], (0, 255, 0), 1)
cv2.circle(compare, (i[0], i[1]), 2, (0, 0, 255), 1)
cv2.imshow('Input', img)
cv2.imshow('Comparison', compare)
cv2.imshow('Clean output', clean)
cv2.waitKey(0)
cv2.destroyAllWindows()
“干净”的圆圈如下所示:
并且,为了比较,原始图像上的叠加层:
如您所见,在此特定图像上使用此方法不会获得完美的结果。参数调整可能会改善结果。
希望有帮助!
【讨论】:
HoughCircles 的方法。对于不规则形状,您可以尝试形态学操作,但这在很大程度上取决于您的实际输入。欢迎随时ask a question!
如果您的问题是特定于圆圈的,您可以使用 Hough Circles 算法在图像中找到圆圈,然后简单地绘制它们。我不知道它是如何在matlab中完成的。在python中你可以使用opencv HoughCircles
如果您正在寻找更通用的解决方案,morphological operators(例如扩张、侵蚀、打开、关闭)可能会感兴趣。
【讨论】: