用opencv中的轮廓检测视网膜图像中的视盘?

问题描述 投票:1回答:1

我有下面的视网膜图像,我想在视盘(视网膜图像中的白色圆形)周围画一个圆。这是原始图像。

enter image description here

我使用了自适应阈值,然后使用了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')

这里是阈值的样子

enter image description here

这是最终输出的轮廓:

enter image description here

理想情况下,我希望有这样的输出。

enter image description here

python opencv image-processing contour
1个回答
3
投票

自适应阈值化失败的原因是滤波器尺寸太小。虽然我们没有弄清楚这一点,但背景中的波浪是相当扰人的。

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

enter image description here


-1
投票

你需要识别更大的结构。理想情况下,你需要的结构大小约为视盘半径的14,以平衡结果和处理时间(用更大的尺寸进行实验,直到可以接受)。

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

© www.soinside.com 2019 - 2024. All rights reserved.