【问题标题】:Detect optic disk in a retina image using contour detection in opencv?使用opencv中的轮廓检测检测视网膜图像中的视盘?
【发布时间】:2020-08-22 16:23:09
【问题描述】:

我有以下视网膜图像,我正在尝试在视盘周围画一个圆圈(视网膜图像中的白色圆形)。这是原图:

我应用了自适应阈值,然后是 cv2.findcontour:

import cv2
def detectBlob(file):
    # read image
    img = cv2.imread(file)
    imageName = file.split('.')[0]
    # convert img to grayscale
    gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

    # do adaptive threshold on gray image
    thresh = cv2.adaptiveThreshold(gray, 255, cv2.ADAPTIVE_THRESH_MEAN_C, cv2.THRESH_BINARY, 101, 3)

    # apply morphology open then close
    kernel = cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (3,3))
    blob = cv2.morphologyEx(thresh, cv2.MORPH_OPEN, kernel)
    kernel = cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (20,20))
    blob = cv2.morphologyEx(blob, cv2.MORPH_CLOSE, kernel)

    # invert blob
    blob = (255 - blob)

    # Get contours
    cnts,hierarchy = cv2.findContours(blob, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)

        # write results to disk
    result = img.copy()
    cv2.drawContours(result, cnts, -1, (0, 0, 255), 3)
    cv2.imwrite(imageName+"_threshold.jpg", thresh)
    cv2.imwrite(imageName+"_blob.jpg", blob)
    cv2.imwrite(imageName+"_contour.jpg", result)

detectBlob('16.png')

这是阈值的样子:

这是轮廓的最终输出:

理想情况下,我正在寻找这样的输出:

【问题讨论】:

    标签: python opencv image-processing contour


    【解决方案1】:

    自适应阈值处理失败,因为过滤器尺寸太小。虽然我们没有弄清楚这一点,但背景中的波浪非常令人不安。

    通过将图像分辨率降低 16 倍并应用范围为 99x99 的自适应滤波器,我获得了一个有趣的结果。

    【讨论】:

      【解决方案2】:

      您需要识别更大的结构。理想情况下,您需要大约 1/4 视盘半径的结构尺寸来平衡结果和处理时间(尝试更大尺寸直到可以接受)。

      或者您可以对图像进行下采样(降低分辨率并使图片更小),这或多或少是一样的,即使您在视盘边界上失去精度。

      【讨论】:

      • 我不理解/不同意这些反对意见。我独立解决了这个问题并得出了相同的结论。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-11-29
      • 2019-12-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-03-31
      相关资源
      最近更新 更多