岭是图像的二阶导数矩阵(也称为 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值以获得适当的解决方案。
例如:
![enter image description here](https://istack.dev59.com/NWSUq.webp)
实际上,在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
)。 - onewhaleid