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

2024-09-28 05:28:56 发布

您现在位置:Python中文网/ 问答频道 /正文

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

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


Tags: 图像img阈值resultcv2kernelblobfile
2条回答

自适应阈值失败,因为过滤器大小太小。虽然我们没有弄清楚,背景中的波是非常令人不安的

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

enter image description here

你需要确定更大的结构。理想情况下,您需要一个大小约为光盘半径1/4的结构,以平衡结果和处理时间(使用更大的尺寸进行试验,直到可以接受为止)

或者你可以减少图像的采样(降低分辨率,使图片变小),这或多或少是一样的,即使你失去了光盘边界的精确性

相关问题 更多 >

    热门问题