Scikit Image - CENSURE Feature Detector



The CENSURE also know as Center Surround Extrema feature detector is a type of scale-invariant keypoint detector widely used in computer vision. It is primary purpose is to identify distinctive keypoints or interest points in an image that are invariant to changes in scale. CENSURE achieves this by analyzing extrema (maxima and minima) within center-surround filters applied to an image at multiple scales. These features are similar in nature to the Laplacian of Gaussian (LoG) features, commonly used for scale-invariant feature detection but can be computed more efficiently, often in real-time applications, using integral images.

Scikit-image offers a flexible way to detect keypoints in images using the CENSURE class. This class is a part of the feature submodule within the scikit-image library.

Using the skimage.feature.CENSURE() Class

The class skimage.feature.CENSURE() is a keypoint detector that is used to extract keypoints or interest points from an image.

Syntax

Following is the syntax of this class −

class skimage.feature.CENSURE(min_scale=1, max_scale=7, mode='DoB', non_max_threshold=0.15, line_threshold=10)

Parameters

Here is the explanation of its parameters −

  • min_scale (int, optional): This parameter specifies the minimum scale to extract keypoints from. The default value is 1.

  • max_scale (int, optional): This parameter specifies the maximum scale to extract keypoints from. The keypoints will be extracted from all scales within the range [min_scale + 1, max_scale - 1]. The filter sizes for different scales are set up so that adjacent scales form an octave. The default value is 7.

  • mode ({'DoB', 'Octagon', 'STAR'}, optional): This parameter determines the type of bi-level filter used to get the scales of the input image. The three modes are −

    • 'DoB': Difference of Boxes filter.

    • 'Octagon': Octagon filter.

    • 'STAR': STAR (Scale-space Blob Detector) filter.

    The choice of mode affects the shape and behavior of the filter used for feature detection. 'DoB' is recommended for better performance, while 'STAR' and 'Octagon' are recommended for better feature detection. The default mode is 'DoB'.

  • non_max_threshold (float, optional): This threshold is used to suppress maximas and minimas with a weak magnitude response obtained after Non-Maximal Suppression. The default value is 0.15.

  • line_threshold (float, optional): This threshold is used for rejecting interest points that have a ratio of principal curvatures greater than this value. The default value is 10.

Here are the attributes of the class −

  • keypoints ( (N, 2) array): This attribute stores the coordinates of the keypoints as (row, col) pairs.

  • scales ((N, ) array): This attribute stores the corresponding scales of the keypoints.

Also this class has a method called detect() which is used to detect CENSURE keypoints along with the corresponding scale.

Syntax

Syntax of the detect() method is −

detect(image)

Parameters

The detect() method Parameter −

  • image (2D ndarray): The input image in which CENSURE keypoints are to be detected.

Example

Here is an example that detects keypoints in the grayscale image using the CENSURE feature detector.

from skimage import io
from skimage.color import rgb2gray
from skimage.feature import CENSURE

# Load the input image and convert it to grayscale
img = rgb2gray(io.imread('Images/black rose.jpg'))

# Create a CENSURE detector
censure = CENSURE()

# Detect CENSURE keypoints in the image
censure.detect(img)

# Access the detected keypoints and scales
keypoints = censure.keypoints
scales = censure.scales

# Print the detected keypoints and their scales
print("Number of keypoints:", len(keypoints))
print("Keypoint coordinates (row, col):")
for keypoint in keypoints:
   print(keypoint)
print("Scales of keypoints:")
print(scales)

Output

Number of keypoints: 17

Keypoint coordinates (row, col):
[ 84 429]
[ 85 430]
[219 169]
[219 327]
[220 303]
[235 158]
[332 180]
[357 310]
[368 311]
[373 310]
[375 336]
[378 344]
[380 341]
[380 395]
[384 401]
[387 408]
[393 286]

Scales of keypoints:
[4 6 2 3 3 3 5 3 2 5 2 4 6 2 5 2 2]

Example

The following example demonstrates the use of the CENSURE feature detector to detect keypoints in both an original and a transformed version of the input image.

from skimage import io
from skimage import transform
from skimage.feature import CENSURE
from skimage.color import rgb2gray
import matplotlib.pyplot as plt

# Load the input image and Convert it to grayscale
image = rgb2gray(io.imread('Images/group chat.jpg'))

# Define an affine transformation for warping the image
tform = transform.AffineTransform(scale=(1.5, 1.5), rotation=0.3, translation=(50, -100))

# Warp the original image using the defined transformation
img_warp = transform.warp(image, tform)

# Create a CENSURE detector
detector = CENSURE()

# Create subplots for displaying the original and transformed images with keypoints
fig, ax = plt.subplots(nrows=1, ncols=2, figsize=(12, 6))

# Detect keypoints in the original image
detector.detect(image)

# Display the original image with keypoints
ax[0].imshow(image, cmap=plt.cm.gray)
ax[0].scatter(detector.keypoints[:, 1], detector.keypoints[:, 0],
   2 ** detector.scales, facecolors='none', edgecolors='r')
ax[0].set_title("Original Image")

# Detect keypoints in the transformed image
detector.detect(img_warp)

# Display the transformed image with keypoints
ax[1].imshow(img_warp, cmap=plt.cm.gray)
ax[1].scatter(detector.keypoints[:, 1], detector.keypoints[:, 0],
   2 ** detector.scales, facecolors='none', edgecolors='r')
ax[1].set_title('Transformed Image')

for a in ax:
   a.axis('off')

plt.tight_layout()
plt.show()

Output

censure detector
Advertisements