能够通过从绿色通道图像中减去模糊图像来对血管进行某种程度的分割,但是当在特定区域(噪声)下移除轮廓时,仍会移除多个血管轮廓。我目前正在删除100区域以下的所有轮廓,但是当我移动到1000或500时,很多血管都破裂了。
首先,我从原始绿色通道图像中减去中值模糊的绿色通道。我尝试了简单的cv2.blur,中值模糊和双边过滤器,但结果实际上是相同的。我不知道是否需要进行某些形态学操作,但是总体目标还是要确保在删除较大的噪声轮廓时仍保持血管轮廓连接。
代码:
import os
import numpy as np
import cv2
def vessels(file):
img = cv2.imread(file)
#green channel extraction to provide most vessel information
imgG = img[:,:,1]
imgblurred = cv2.blur(imgG, (100,100))
f5 = imgG - imgblurred
ret,f6 = cv2.threshold(f5,15,255,cv2.THRESH_BINARY)
mask = np.ones(f5.shape[:2], dtype="uint8") * 255
im2, contours, hierarchy = cv2.findContours(f6.copy(),cv2.RETR_LIST,cv2.CHAIN_APPROX_SIMPLE)
for cnt in contours:
if cv2.contourArea(cnt) <= 100:
cv2.drawContours(mask, [cnt], -1, 0, -1)
im = cv2.bitwise_and(f5, f5, mask=mask)
ret,fin = cv2.threshold(im,15,255,cv2.THRESH_BINARY_INV)
return fin