首页 > 解决方案 > 图像分割 - 如何检测这种静脉连接?(地标)

问题描述

蜜蜂静脉

我需要检测翼蜂的静脉连接处(图像只是一个例子)。我使用 opencv - python。

ps:可能图片质量损失了一点点,但是图片都是连接一个像素宽的。

标签: pythonimageopencv

解决方案


这是个有趣的问题。我得到的结果并不完美,但这可能是一个好的开始。我用只查看内核边缘的内核过滤了图像。这个想法是,一个连接点至少有 3 条线穿过内核边缘,而常规线只有 2 条。这意味着当内核超过一个连接点时,结果值会更高,因此阈值会显示它们.
由于线条的性质,存在一些正面价值和一些假负面。很可能会多次找到单个关节,因此您必须考虑到这一点。您可以通过绘制小点并检测这些点来使它们独一无二。

结果:

在此处输入图像描述

代码:

    import cv2
    import numpy as np
    # load the image as grayscale
    img = cv2.imread('xqXid.png',0)
    # make a copy to display result
    im_or = img.copy()
    # convert image to larger datatyoe
    img.astype(np.int32)
    # create kernel 
    kernel = np.ones((7,7))
    kernel[2:5,2:5] = 0
    print(kernel)
    #apply kernel
    res = cv2.filter2D(img,3,kernel)
    # filter results
    loc = np.where(res > 2800)
    print(len(loc[0]))
    #draw circles on found locations
    for x in range(len(loc[0])):
            cv2.circle(im_or,(loc[1][x],loc[0][x]),10,(127),5)
    #display result
    cv2.imshow('Result',im_or)
    cv2.waitKey(0)
    cv2.destroyAllWindows()

注意:您可以尝试调整内核和阈值。例如,使用上面的代码,我得到了 126 个匹配项。但是当我使用

kernel = np.ones((5,5))
kernel[1:4,1:4] = 0

有阈值

loc = np.where(res > 1550)

我在这些位置获得了 33 场比赛:

在此处输入图像描述


推荐阅读