【问题标题】:Need to find the outer boundary size of droplets in python需要在python中找到液滴的外边界大小
【发布时间】:2023-01-14 22:18:36
【问题描述】:

我正在尝试使用 python 找到沿管长的所有水滴的外边界大小。

在精明的边缘检测之后,我很难区分外部和内部边界。有人能帮帮我吗?

我使用的图像预处理是这样的:

# load the image, convert it to grayscale, and blur it slightly
gray = cv2.GaussianBlur(imc, (5, 5), 0)
# perform edge detection, then perform a dilation + erosion to
# close gaps in between object edges
dilate = cv2.dilate(gray, None, iterations=1)
#cv2.imshow('dilated',dilate)
erode = cv2.erode(dilate, None, iterations=1)
#cv2.imshow('eroded',erode)
edged = cv2.Canny(erode,230,230)
#cv2.imshow('%deroded' %count,edged)
  1. 这段代码很容易给我内边缘,但我想要外边缘。

  2. 您可以看到液滴边界足够厚并且因情况而异。

  3. 我必须按顺序处理 4000 张图像。请指导我。

  4. 我无法区分液滴边界和管边界。

    如何消除内边缘,只过滤外边缘?

    以上一个是接近预期的输出。

【问题讨论】:

  • 为清楚起见,您可能希望提供预期的输出图像。不错的微流体液滴顺便说一句;)
  • 在提问时,确保你发布的标签是好的,因为即使你在你的问题一天前添加它们,大多数人也不会再看到它——你可以尝试阈值(或不),然后是形态学(打开或关闭)这将有望留下液滴的厚暗边界,同时擦除所有较窄的暗特征

标签: python opencv image-processing computer-vision


【解决方案1】:

精明的阈值步骤和改进的阈值将仅提供外边缘。我执行了初步的直方图分析数据探索(有关详细信息,请参阅 OpenCV 的 calcHist 函数)以衡量这些阈值。

执行阈值步骤后,您可以使用阈值图像或精明结果来查找轮廓,如上图所示。

如果您将来仍能同时找到内边缘和外边缘,我建议按边界框中心对轮廓进行分组,然后过滤掉共享相似中心的较小轮廓,以及面积稍大的较大轮廓。

# gray = cv2.GaussianBlur(im, (5, 5), 0)

dilate = cv2.dilate(gray, None, iterations=1)
erode  = cv2.erode(dilate, None, iterations=1)

_, thresh = cv2.threshold(erode, 108, 255, cv2.THRESH_BINARY)
edged    = cv2.Canny(thresh, 144, 250)

canny_cnts, _  = cv2.findContours(edged, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
thresh_cnts, _ = cv2.findContours(255-thresh[:,:,0], cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)

f, ax = plt.subplots(3,1,figsize=(20,7))

for a, i, t in zip(ax, [erode, thresh, edged], ['Eroded', 'Thresholded', 'Canny']):
    a.imshow(i, 'gray')
    a.axis('off')
    a.set_title(t)

for a, cnts in zip(ax[1:], [thresh_cnts, canny_cnts]):
    for cnt, col in zip([ c[:,0] for c in cnts ], colors):
        a.plot( cnt[:,0], cnt[:,1], color=col, lw=2)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-02-27
    • 2015-07-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多