在skimage中有一个替代方法,由Xie, Yonghong和Qiang Ji制作并发表于“一种新的高效椭圆检测方法”。Pattern Recognition, 2002. Proceedings. 16th International Conference on. Vol. 2. IEEE, 2002.他们的椭圆检测代码相对较慢,示例需要大约70秒;与网站声称的“28秒”相比。如果您有conda或pip:“name”安装scikit-image并尝试一下...您可以在此处找到他们的代码
here或作为复制/粘贴下方:
import matplotlib.pyplot as plt
from skimage import data, color, img_as_ubyte
from skimage.feature import canny
from skimage.transform import hough_ellipse
from skimage.draw import ellipse_perimeter
image_rgb = data.coffee()[0:220, 160:420]
image_gray = color.rgb2gray(image_rgb)
edges = canny(image_gray, sigma=2.0,
low_threshold=0.55, high_threshold=0.8)
result = hough_ellipse(edges, accuracy=20, threshold=250,
min_size=100, max_size=120)
result.sort(order='accumulator')
best = list(result[-1])
yc, xc, a, b = [int(round(x)) for x in best[1:5]]
orientation = best[5]
cy, cx = ellipse_perimeter(yc, xc, a, b, orientation)
image_rgb[cy, cx] = (0, 0, 255)
edges = color.gray2rgb(img_as_ubyte(edges))
edges[cy, cx] = (250, 0, 0)
fig2, (ax1, ax2) = plt.subplots(ncols=2, nrows=1, figsize=(8, 4), sharex=True,
sharey=True,
subplot_kw={'adjustable':'box'})
ax1.set_title('Original picture')
ax1.imshow(image_rgb)
ax2.set_title('Edge (white) and result (red)')
ax2.imshow(edges)
plt.show()