如何使用 scikit 填充二值图像的漏洞?

发布于 2025-01-15 12:30:17 字数 1027 浏览 6 评论 0原文

对于图像分析问题,我想输出一个背景为深色而硬币为白色的二值图像。我应该使用 skimage 而不是 CV2。

我已经完成了一些编码以得出以下图像:
Canny-硬币的边缘图像

运行该图像的代码是:

im_coin = io.imread("coins.jpg") 
imgGaussF = scipy.ndimage.gaussian_filter(im_coin, sigma=2.5)

im = img_as_ubyte(imgGaussF)

edge_canny = feature.canny(im, sigma=1,low_threshold=10, high_threshold=50)

plt.figure(figsize=(15,8))
plt.subplot(131), plt.imshow(edge_canny, cmap='gray'), plt.axis('off'), plt.title('Canny Edge Dectector \n (sigma = 1, T1=10, T2 = 50)')

现在我应该填补上面显示的图像的漏洞。

我尝试过:

edge_canny = edge_canny > 0.5

im_fill1 = binary_fill_holes(edge_canny, structure=np.ones((3,3)))

plt.gray()
plt.figure(figsize = (15,12))
plt.subplot(132), plt.imshow(im_fill1), plt.axis('off'), plt.title('Binary holes filling square size = 3 ')

但这并不能解决问题。它返回相同的图像,没有填充任何孔。谁能帮助我吗?

注意:我应该使用 skimage 而不是 cv2

For an image analysis problem, I want to output a binary image where the background is dark and the coins are white. I'm supposed to use skimage and not CV2.

I've already done some coding to come up with the following image:
Canny-edge image of coins

The code that runs this image is:

im_coin = io.imread("coins.jpg") 
imgGaussF = scipy.ndimage.gaussian_filter(im_coin, sigma=2.5)

im = img_as_ubyte(imgGaussF)

edge_canny = feature.canny(im, sigma=1,low_threshold=10, high_threshold=50)

plt.figure(figsize=(15,8))
plt.subplot(131), plt.imshow(edge_canny, cmap='gray'), plt.axis('off'), plt.title('Canny Edge Dectector \n (sigma = 1, T1=10, T2 = 50)')

Now I'm supposed to fill the holes of the image presented above.

I tried:

edge_canny = edge_canny > 0.5

im_fill1 = binary_fill_holes(edge_canny, structure=np.ones((3,3)))

plt.gray()
plt.figure(figsize = (15,12))
plt.subplot(132), plt.imshow(im_fill1), plt.axis('off'), plt.title('Binary holes filling square size = 3 ')

But this doesn't do the trick. It returns the same image with no holes filled. Can anyone help me?

Note: I'm supposed to use skimage instead of cv2

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文