【发布时间】:2019-02-09 08:39:13
【问题描述】:
我有大约 30 张这样的 SEM(扫描电子显微镜)图像:
您看到的是玻璃基板上的光刻胶柱。 我想做的是得到 x 和 y 方向的平均直径以及 x 和 y 方向的平均周期。
现在,与其手动进行所有测量,我想知道是否有办法使用 python 和 opencv 实现自动化?
编辑: 我尝试了以下代码,它似乎正在检测圆圈,但我真正需要的是椭圆,因为我需要 x 和 y 方向的直径。
...我还不太明白如何获得秤?
import numpy as np
import cv2
from matplotlib import pyplot as plt
img = cv2.imread("01.jpg",0)
output = img.copy()
edged = cv2.Canny(img, 10, 300)
edged = cv2.dilate(edged, None, iterations=1)
edged = cv2.erode(edged, None, iterations=1)
# detect circles in the image
circles = cv2.HoughCircles(edged, cv2.HOUGH_GRADIENT, 1.2, 100)
# ensure at least some circles were found
if circles is not None:
# convert the (x, y) coordinates and radius of the circles to integers
circles = np.round(circles).astype("int")
# loop over the (x, y) coordinates and radius of the circles
for (x, y, r) in circles[0]:
print(x,y,r)
# draw the circle in the output image, then draw a rectangle
# corresponding to the center of the circle
cv2.circle(output, (x, y), r, (0, 255, 0), 4)
cv2.rectangle(output, (x - 5, y - 5), (x + 5, y + 5), (0, 128, 255), -1)
# show the output image
plt.imshow(output, cmap = 'gray', interpolation = 'bicubic')
plt.xticks([]), plt.yticks([]) # to hide tick values on X and Y axis
plt.figure()
plt.show()
灵感来源:https://www.pyimagesearch.com/2014/07/21/detecting-circles-images-using-opencv-hough-circles/
【问题讨论】:
-
一些预处理可能会有所帮助。首先,我会切断底部的文本区域。找出所有明亮的大斑点。将图像划分为 roi,使得每个 roi 只包含一个 blob。丢弃包含部分 blob 的 roi(即 blob 靠近边缘的位置)。对剩余的 ROI 进行进一步分析。 (哦,不使用 JPEG 作为输入图像的荣誉)
-
既然你提到了椭圆,你可以在柱子的轮廓上做
cv2.fitEllipse。
标签: python image opencv image-processing