简体   繁体   English

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

[英]Detect optic disk in a retina image using contour detection in opencv?

I have the following retina image and I'm trying to draw a circle around the optic disk (the white round shape in retinal image).我有以下视网膜图像,我试图在视盘周围画一个圆圈(视网膜图像中的白色圆形)。 Here is the original image:这是原始图像:

在此处输入图像描述

I applied adaptive thresholding then cv2.findcontour:我应用了自适应阈值然后 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')

Here is the what the threshold looks like:这是阈值的样子:

在此处输入图像描述

Here is the final output of contours:这是轮廓的最终 output:

在此处输入图像描述

Ideally I'm looking for such an output:理想情况下,我正在寻找这样的 output:

在此处输入图像描述

Adaptive thresholding fails because the filter size is much too small.自适应阈值化失败是因为过滤器尺寸太小。 And though we don't figure this out, the waves in the background are quite perturbating.虽然我们没有弄清楚这一点,但背景中的波浪非常令人不安。

I obtained an interesting result by reducing the image resolution by a factor 16 and applying an adaptive filter of extent 99x99.通过将图像分辨率降低 16 倍并应用范围为 99x99 的自适应滤波器,我获得了一个有趣的结果。

在此处输入图像描述

You need to identify larger structures.您需要识别更大的结构。 Ideally you need a structure size about 1/4 of the radius of the optic disk to balance results and processing time (experiment with larger sizes until acceptable).理想情况下,您需要大约 1/4 视盘半径的结构尺寸来平衡结果和处理时间(用更大的尺寸进行实验直到可以接受)。

Or you could downsample the image (reduce the resolution and make the picture smaller), which is more or less the same thing, even if you lose precision on the optic disk borders.或者您可以对图像进行下采样(降低分辨率并使图片更小),这或多或少是一回事,即使您在视盘边界上失去了精度。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM