Advertisement

眼底图像-血管检测

阅读量:
复制代码
 对眼底图像中心区进行血管的检测。用了HoughLinesP()直线检测法,附上执行时的三张图

    
 代码如下:
    
 # 分离出 图像中心的绿色通道
    
 img_ori = cv2.imread('./dataset/1.jpg')
    
 img_resized = cv2.resize(img_ori, (width, height), interpolation=cv2.INTER_CUBIC)
    
 cv2.imshow('resize', img_resized )
    
 b,g,r = cv2.split(img_resized)
    
  
    
 # 进行 CLAHE 处理,提取绿色通道
    
 clahe = cv2.createCLAHE(clipLimit=2.0, tileGridSize=(8, 8))
    
 img_clahe_green = clahe.apply(g)
    
 cv2.imshow('green', img_clahe_green)
    
 # 检测图像绿色通道中的血管,画直线
    
 line_detect_possible(img_clahe_green ,11)
    
    
    
    
    代码解读

--------下面是血管检测函数 ------------------------

从整体图像中提取各个小窗口的图像部分,并通过调用OpenCV中的HoughLinesP函数来识别各个小窗口中的直线特征。随后,在整体图像上绘制这些检测到的直线。

比在整图中用HoughLinesP()检测效果好。

复制代码
 def line_detect_possible(img_src,size):

    
     width = img_src.shape[0] 
    
     height = img_src.shape[1]
    
     gaus = cv2.GaussianBlur(img_src, (3, 3), 0)
    
     edges = cv2.Canny(gaus, 40, 230, apertureSize=3)
    
  
    
     img_new1 = edges
    
     line_num = 0
    
  
    
     for i in range(0, width - size,size):
    
     for j in range(0, height - size,size):
    
         img_region_ij = img_new1[i:i + size, j:j + size]  # 提取 小窗口内图像
    
         # 函数将通过步长为1的半径和步长为π/180的角来搜索所有可能的直线
    
         cv2.imshow("regionij", img_region_ij)        # 调试时查看用,实际运行时删除。
    
         lines = cv2.HoughLinesP(img_region_ij, 1, np.pi / 180, 5, minLineLength=5, maxLineGap=5)
    
         if (lines is None) or (len(lines) == 0):
    
             continue                 # 小窗口内无直线,继续到下一个窗口
    
         else:
    
             for x1, y1, x2, y2 in lines[0]:
    
                 line_num += 1
    
                 cv2.line(img_new1, (i+x1, j+y1), (i+x2, j+y2), (0, 255, 0), 2)
    
  
    
     cv2.imshow("line1", img_new1)
    
     return line_num
    
    
    
    
    代码解读

全部评论 (0)

还没有任何评论哟~