How to use ridge detection filter in opencv
Ridges are eigenvalues of matrix of second order derivate of image, also known as hessian matrix.
Using the above information, you can easily write a ridge detector using functionality provided by 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
Here, i1 returns local maxima ridges and i2 returns local minima ridges. You can tinker around with sigma values to get an appropriate solution. Example:
Actually, in Python/OpenCV, you can do something like this
image = cv2.imread('retina.tif')
ridge_filter = cv2.ximgproc.RidgeDetectionFilter_create()
ridges = ridge_filter.getRidgeFilteredImage(image)
Parameters for cv2.ximgproc.RidgeDetectionFilter_create
include:
@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
Source - https://docs.opencv.org/trunk/d4/d36/classcv_1_1ximgproc_1_1RidgeDetectionFilter.html