如何使用python计算图像中的对象?

新手上路,请多包涵

我正在尝试计算此图像中的液滴数量以及这些液滴所覆盖区域的覆盖百分比。我试图将此图像转换为黑白图像,但这些水滴的中心颜色似乎与背景太相似了。所以我只得到了类似第二张图片的东西。有什么办法可以解决这个问题或者有什么更好的想法吗?非常感谢。

源图像

转换图像

原文由 JIAHAO HUANG 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 510
1 个回答

您可以使用 scipy.ndimage.binary_fill_holes 填充二进制图像的孔。我还建议使用自动阈值方法,例如 Otsu 的方法(在 scikit-image 中可用)。 在此处输入图像描述

 from skimage import io, filters
from scipy import ndimage
import matplotlib.pyplot as plt

im = io.imread('ba3g0.jpg', as_grey=True)
val = filters.threshold_otsu(im)
drops = ndimage.binary_fill_holes(im < val)
plt.imshow(drops, cmap='gray')
plt.show()

对于滴数,您可以使用另一个函数 scikit-image

 from skimage import measure
labels = measure.label(drops)
print(labels.max())

而对于报道

print('coverage is %f' %(drops.mean()))

原文由 Emmanuelle Gouillart 发布,翻译遵循 CC BY-SA 3.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题