python - 使用 Python 进行视网膜血管分割

标签 python opencv image-processing deep-learning image-segmentation

我有以下视网膜图像,我正在尝试追踪血管(从圆圈中出来的较暗的线条)。这是原始图像:
enter image description here
我尝试使用除法归一化对图像进行阈值处理,然后对轮廓区域进行过滤(根据不同的 stackoverflow 解决方案):

import cv2
import numpy as np

# read the image
img = cv2.imread('retina_eye.jpg')

# convert to gray
gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)

# apply morphology
kernel = cv2.getStructuringElement(cv2.MORPH_RECT , (5,5))
morph = cv2.morphologyEx(gray, cv2.MORPH_DILATE, kernel)

# divide gray by morphology image
division = cv2.divide(gray, morph, scale=255)

# threshold
thresh = cv2.threshold(division, 0, 255, cv2.THRESH_OTSU )[1] 

# invert
thresh = 255 - thresh

# find contours and discard contours with small areas
mask = np.zeros_like(thresh)
contours = cv2.findContours(thresh, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
contours = contours[0] if len(contours) == 2 else contours[1]

area_thresh = 10000
for cntr in contours:
    area = cv2.contourArea(cntr)
    if area > area_thresh:
        cv2.drawContours(mask, [cntr], -1, 255, 2)

# apply mask to thresh
result1 = cv2.bitwise_and(thresh, mask)
mask = cv2.merge([mask,mask,mask])
result2 = cv2.bitwise_and(img, mask)

# save results
cv2.imwrite('retina_eye_division.jpg',division)
cv2.imwrite('retina_eye_thresh.jpg',thresh)
cv2.imwrite('retina_eye_mask.jpg',mask)
cv2.imwrite('retina_eye_result1.jpg',result1)
cv2.imwrite('retina_eye_result2.jpg',result2)

# show results
cv2.imshow('morph', morph)  
cv2.imshow('division', division)  
cv2.imshow('thresh', thresh)  
cv2.imshow('mask', mask)  
cv2.imshow('result1', result1)  
cv2.imshow('result2', result2)  
cv2.waitKey(0)
cv2.destroyAllWindows()
这是我得到的最终输出:
enter image description here
它最终追踪了船只,但它也有一些背景噪音。
理想情况下,我正在寻找这个输出:
enter image description here
实现这一结果的任何建议?

最佳答案

我一直在研究用深度学习进行视网膜血管分割的课题,你问的问题基本一样。
我想和你分享我的研究。
在我们想要分割的图像部分的强度或对比度非常低的情况下,我们必须应用 CLAHE(对比度限制自适应直方图均衡) .这是获得非常好的结果的非常强大的技术。我想让你试试。让我也为此提供一些代码:

import cv2

bgr = cv2.imread(retinal_image)
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
clahe = cv2.createCLAHE(clipLimit=2.0, tileGridSize=(8, 8))
equalized = clahe.apply(gray)
更多的你也可以使用 非局部平均值 用于图像去噪。
如果您想了解它是如何完成的完整过程,我建议您通过 this easy paper它涵盖了整个过程。

关于python - 使用 Python 进行视网膜血管分割,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62587153/

相关文章:

iphone - 如何让示例运行 Open CV

java - Java中的图像输入输出

image-processing - 单个位图图像的 H.264/H.265 压缩

python - 计算标记化网址中的单词数

python - wxPython 中的 Pygments?

python - SQLAlchemy - 什么是 declarative_base

ios - 无法在 iOS 10 上使用 OpenCV 3.1 使用 VideoWriter 创建文件

python - 树莓派和 OpenCV 的问题

c# - 如何提高网络摄像头视频输入的帧率?埃姆古简历

python - 为什么 coverage.py 不能正确测量 Flask 的 runserver 命令?