Scikit Image − Frangi Filter



The Frangi filter is a commonly used technique in image processing for detecting ridge-like structures within an image. These structures can take various forms, such as neurites, tubes, vessels, wrinkles, or rivers. The Frangi filter belongs to a class of ridge filters that rely on the eigenvalues of the Hessian matrix of image intensities to identify ridge structures.

This filter can be used to enhance and analyze the features of interest in an image. The choice of parameters like alpha, beta, and gamma can be adjusted to fine-tune the filter's behavior for a specific application.

The scikit image library provides the frangi() function in the filters module to apply the Frangi vesselness filter on images.

Using the skimage.filters.frangi() function

The filters.frangi() function is used to filter an image with the Frangi vesselness filter. This filter is primarily used to detect continuous ridges in an image, such as vessels, wrinkles, or rivers. It can be used to calculate the fraction of the whole image containing such objects.

This filter works on 2-D and 3-D images and calculates the similarity of image regions to vessels using the eigenvectors of the Hessian matrix.

Syntax

Following is the syntax of this function −

skimage.filters.frangi(image, sigmas=range(1, 10, 2), scale_range=None, scale_step=None, alpha=0.5, beta=0.5, gamma=None, black_ridges=True, mode='reflect', cval=0)

Parameters

Here's an explanation of the parameters −

  • Image ((N, M[, P]) ndarray): This parameter is the input image on which Frangi vesselness filter will be applied.
  • Sigmas (iterable of floats, optional): it specifying the scales of the filter. i.e., np.arange(scale_range[0], scale_range[1], scale_step).
  • scale_range (optional): A 2-tuple of floats that defines the range of sigmas used for filtering.
  • Scale_step (float, optional): This parameter specifies the step size between sigmas.
  • alpha (float, optional): Frangi correction constant that adjusts the filter’s sensitivity to deviation from a plate-like structure.
  • Beta (float, optional): The Frangi correction constant, adjusting the filter's sensitivity to deviations from blob-like structures.
  • Gamma (float, optional): The Frangi correction constant, adjusting the filter's sensitivity to areas with high variance, texture, or structure. The default value is None, which uses half of the maximum Hessian norm.
  • Black_ridges (boolean, optional): The default value is True, determining whether the filter detects black ridges (True) or white ridges (False).
  • Mode (string, optional): This parameter specifies how to handle values outside the image borders, with options like 'constant', 'reflect', 'wrap', 'nearest', or 'mirror'.
  • Cval (float, optional): This is used in conjunction with mode 'constant' to specify the value outside the image boundaries.

Return value

The function returns a filtered image as a ndarray, where each pixel represents the maximum response across all scales.

Example

This example demonstrates the use of the skimage.filters.frangi() function with its default parameter values −

import matplotlib.pyplot as plt
from skimage.filters import frangi
from skimage import io, color

# Load the input image 
in_image = io.imread('Images/tree.jpg')
x_0 = 250
y_0 = 100
width = 250
height = 150
# Crop the image to the specified region and convert it to grayscale
image = color.rgb2gray(in_image[y_0:(y_0 + height), x_0:(x_0 + width)])

# Apply the Frangi filter with the default values
filtered_image = frangi(image)

# Plot the original and filtered images
plt.figure(figsize=(10, 5))

plt.subplot(1, 2, 1)
plt.imshow(image, cmap='gray')
plt.title('Original Image')
plt.axis('off')

plt.subplot(1, 2, 2)
plt.imshow(filtered_image, cmap='gray')
plt.title('Frangi Filter Result')
plt.axis('off')

plt.tight_layout()
plt.show()

Output

Frangi Filter

Example

The following example demonstrates how the Frangi filter can be used to enhance and visualize ridge-like structures in an image −

from skimage import io
from skimage import color
from skimage.filters import frangi
import matplotlib.pyplot as plt

# Load the input image 
in_image = io.imread('Images/tree.jpg')
x_0 = 250
y_0 = 100
width = 250
height = 150

# Crop the image to the specified region and convert it to grayscale
image = color.rgb2gray(in_image[y_0:(y_0 + height), x_0:(x_0 + width)])

# Apply the Frangi filter with black_ridges=True
result_black_ridges = frangi(image, black_ridges=True, sigmas=[1])
result_black_ridges_sigmas = frangi(image, black_ridges=True, sigmas=range(1, 5))

# Apply the Frangi filter with black_ridges=False
result_white_ridges = frangi(image, black_ridges=False, sigmas=[1])
result_white_ridges_sigmas = frangi(image, black_ridges=False, sigmas=range(1, 5))

# Plot the original, filtered (both black_ridges=True and black_ridges=False) images
fig, axes = plt.subplots(2, 3, figsize=(10, 5))
ax = axes.ravel()

# Display the Original Image
ax[0].imshow(image, cmap='gray')
ax[0].set_title('Original Image')
ax[0].axis('off')

# Display the Result with black_ridges=True
ax[1].imshow(result_black_ridges, cmap='gray')
ax[1].axis('off')
ax[1].set_title('Frangi Filter (black_ridges=True)\n \N{GREEK SMALL LETTER SIGMA}=[1]')

# Display the Result with black_ridges=False
ax[2].imshow(result_white_ridges, cmap='gray')
ax[2].axis('off')
ax[2].set_title('Frangi Filter (black_ridges=False)\n \N{GREEK SMALL LETTER SIGMA} =[1]')

# Display the Original Image again (for the second row)
ax[3].imshow(image, cmap='gray')
ax[3].axis('off')
ax[3].set_title('Original Image')

# Display the Result with black_ridges=True 
ax[4].imshow(result_black_ridges_sigmas, cmap='gray')
ax[4].axis('off')
ax[4].set_title('Frangi Filter (black_ridges=True)\n \N{GREEK SMALL LETTER SIGMA} =[1,2,3,4]')

# Display the Result with black_ridges=False 
ax[5].imshow(result_white_ridges_sigmas, cmap='gray')
ax[5].axis('off')
ax[5].set_title('Frangi Filter (black_ridges=False)\n \N{GREEK SMALL LETTER SIGMA} =[1,2,3,4]')

plt.tight_layout()
plt.show()

Output

Frangi Filter
Advertisements