【问题标题】:How to use ridge detection filter in opencv如何在opencv中使用脊检测过滤器
【发布时间】:2018-02-11 03:11:19
【问题描述】:

我正在尝试将 ridge/valley 过滤器与 opencv-python 一起使用。而且我刚刚查看了openCV官方website中的文档,里面告诉我要使用

out = cv.ximgproc_RidgeDetectionFilter.getRidgeFilteredImage( _img[, out] ).

但是,经过尝试,这个函数似乎在 cv2(python) 中不存在。是否有使用 openCV 或任何其他可用方法的替代方法?

【问题讨论】:

    标签: python opencv computer-vision


    【解决方案1】:

    岭是图像的二阶导数矩阵的特征值,也称为hessian矩阵。

    使用上述信息,您可以使用 scikit-image 提供的功能轻松编写脊检测器

    from skimage.features import hessian_matrix, hessian_matrix_eigvals
    def detect_ridges(gray, sigma=3.0):
        hxx, hyy, hxy = hessian_matrix(gray, sigma)
        i1, i2 = hessian_matrix_eigvals(hxx, hxy, hyy)
        return i1, i2
    

    这里,i1 返回局部最大值脊,而 i2 返回局部最小值脊。您可以修改 sigma 值以获得适当的解决方案。 示例:

    实际上,在 Python/OpenCV 中,你可以这样做

    image = cv2.imread('retina.tif')
    ridge_filter = cv2.ximgproc.RidgeDetectionFilter_create()
    ridges = ridge_filter.getRidgeFilteredImage(image)
    

    cv2.ximgproc.RidgeDetectionFilter_create的参数包括:

    @param ddepth  Specifies output image depth. Defualt is CV_32FC1
    @param dx Order of derivative x, default is 1 .   
    @param dy  Order of derivative y, default is 1 .   
    @param ksize Sobel kernel size , default is 3 .   
    @param out_dtype Converted format for output, default is CV_8UC1 .   
    @param scale Optional scale value for derivative values, default is 1 .   
    @param delta  Optional bias added to output, default is 0 .   
    @param borderType Pixel extrapolation  method, default is BORDER_DEFAULT
    

    来源 - https://docs.opencv.org/trunk/d4/d36/classcv_1_1ximgproc_1_1RidgeDetectionFilter.html

    【讨论】:

    • 模块名为skimage.feature(不是skimage.features)
    【解决方案2】:

    目前(scikit-image 1.14.1),接受的答案不起作用。 这是一个版本:

    import cv2
    import matplotlib.pyplot as plt
    from skimage.feature import hessian_matrix, hessian_matrix_eigvals
    
    src_path = 'Fundus_photograph_of_normal_left_eye.jpg'
    
    def detect_ridges(gray, sigma=1.0):
        H_elems = hessian_matrix(gray, sigma=sigma, order='rc')
        maxima_ridges, minima_ridges = hessian_matrix_eigvals(H_elems)
        return maxima_ridges, minima_ridges
    
    def plot_images(*images):
        images = list(images)
        n = len(images)
        fig, ax = plt.subplots(ncols=n, sharey=True)
        for i, img in enumerate(images):
            ax[i].imshow(img, cmap='gray')
            ax[i].axis('off')
        plt.subplots_adjust(left=0.03, bottom=0.03, right=0.97, top=0.97)
        plt.show()
    
    img = cv2.imread(src_path, 0) # 0 imports a grayscale
    if img is None:
        raise(ValueError(f"Image didn\'t load. Check that '{src_path}' exists."))
    
    a, b = detect_ridges(img, sigma=3.0)
    
    plot_images(img, a, b)
    

    图片来源:https://en.wikipedia.org/wiki/Fundus_photography#/media/File:Fundus_photograph_of_normal_left_eye.jpg

    【讨论】:

      【解决方案3】:

      有一个基于“Steger, C., 1998. 曲线结构的无偏检测器。IEEE Transactions on Pattern Analysis and Machine Intelligence, 20(2), pp.113–125”的脊检测算法版本。纸。

      它不使用openCV,因此我希望不要跑题,但您可以根据自己的目的修改代码

      这里是链接: https://gitlab.gwdg.de/sphire/ridge_detection

      可以直接通过pip安装 https://pypi.org/project/ridge-detection/

      【讨论】:

        猜你喜欢
        • 2019-05-18
        • 1970-01-01
        • 1970-01-01
        • 2016-08-03
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-10-21
        • 2016-02-13
        相关资源
        最近更新 更多