我有一些类似这样的透射电子显微镜图像:
有没有Python模块可以帮助我分析这张图片,特别是在图片中检测出原子(圆形)?
由于TEM图像的质量相当糟糕,因此我需要一种足够强大的方法来区分什么是原子和什么不是。
我可以很容易地使用PIL打开图片并对其进行处理,但我希望能找到一种算法来检测圆形。
如果没有这样的工具,是否有人知道如何制作自己的算法来完成这个任务?
我有一些类似这样的透射电子显微镜图像:
有没有Python模块可以帮助我分析这张图片,特别是在图片中检测出原子(圆形)?
由于TEM图像的质量相当糟糕,因此我需要一种足够强大的方法来区分什么是原子和什么不是。
我可以很容易地使用PIL打开图片并对其进行处理,但我希望能找到一种算法来检测圆形。
如果没有这样的工具,是否有人知道如何制作自己的算法来完成这个任务?
import cv2
image = cv2.imread('atoms.png')
image2 = cv2.cvtColor(
image,
cv2.COLOR_BGR2GRAY,
)
image2 = cv2.GaussianBlur(
image2,
ksize=(9,9),
sigmaX=8,
sigmaY=8,
)
cv2.imwrite('blurred.png', image2)
hello, image2 = cv2.threshold(
image2,
thresh=95,
maxval=255,
type=cv2.THRESH_BINARY_INV,
)
cv2.imwrite('thresholded.png', image2)
contours, hier = cv2.findContours(
image2, # Note: findContours() changes the image.
mode=cv2.RETR_EXTERNAL,
method=cv2.CHAIN_APPROX_NONE,
)
print('Number of contours: {0}'.format(len(contours)))
cv2.drawContours(
image,
contours=contours,
contourIdx=-1,
color=(0,255,0),
thickness=2,
)
cv2.imwrite('augmented.png', image)
cv2.imshow('hello', image)
cv2.waitKey(-1)
标准输出如下:
Number of contours: 46