Mahotas 简明教程

Mahotas - SURF Dense Points

SURF(加速稳健特征)是一种用于检测和描述图像中感兴趣点的算法。这些点被称为“密集点”或“关键点”,因为它们密集地存在于图像中,不同于仅出现在特定区域的稀疏点。

SURF (Speeded Up Robust Features) is an algorithm used to detect and describe points of interest in images. These points are called "dense points" or "keypoints" because they are densely present across the image, unlike sparse points which are only found in specific areas.

SURF 算法在不同尺度分析整个图像,并识别强度大幅变化的区域。

The SURF algorithm analyzes the entire image at various scales and identifies areas where the intensity changes significantly.

这些区域被视为潜在的关键点。它们是有趣的区域,包含独特且显着的模式。

These areas are considered as potential keypoints. They are areas of interest that contain unique and distinctive patterns.

SURF Dense Points in Mahotas

在 Mahotas 中,我们使用 mahotas.features.surf.dense() 函数来计算 SURF 密集点处的描述符。描述符本质上是特征向量,描述图像中像素的局部特征,例如它们的强度梯度和方向。

In Mahotas, we use the mahotas.features.surf.dense() function to compute the descriptors at SURF dense points. Descriptors are essentially feature vectors that describe the local characteristics of pixels in an image, such as their intensity gradients and orientations.

为了生成这些描述符,该函数在图像上创建了一个点网格,每个点由特定的距离分隔。在网格中的每个点,确定一个“兴趣点”。

To generate these descriptors, the function creates a grid of points across the image, with each point separated by a specific distance. At each point in the grid, an "interest point" is determined.

这些兴趣点是捕获图像详细信息的位置。一旦识别出兴趣点,就计算出密集 SURF 描述符。

These interest points are locations where detailed information about the image is captured. Once the interest points are identified, the dense SURF descriptors are computed.

The mahotas.features.surf.dense() function

mahotas.features.surf.dense() 函数将灰度图像作为输入,并返回包含描述符的数组。

The mahotas.features.surf.dense() function takes a grayscale image as an input and returns an array containing the descriptors.

这个数组通常具有一个结构:每行对应不同的兴趣点,列表示该点的描述符特征值。

This array typically has a structure where each row corresponds to a different interest point, and the columns represent the values of the descriptor features for that point.

以下是 mahotas 中 surf.dense() 函数的基本语法:

Following is the basic syntax of the surf.dense() function in mahotas −

mahotas.features.surf.dense(f, spacing, scale={np.sqrt(spacing)},
is_integral=False, include_interest_point=False)

其中,

Where,

  1. f − It is the input grayscale image.

  2. spacing − It determines the distance between the adjacent keypoints.

  3. scale (optional) − It specifies the spacing used when computing the descriptors (default is square root of spacing).

  4. is_integral (optional) − It is a flag which indicates whether input image is integer or not (default is 'False').

  5. include_interest_point (optional) − It is also a flag that indicates whether to return the interest points with the SURF points (default is 'False').

在以下示例中,我们使用 mh.features.surf.dense() 函数计算图像的 SURF 稠密点。

In the following example, we are computing the SURF dense points of an image using the mh.features.surf.dense() function.

import mahotas as mh
from mahotas.features import surf
import numpy as np
import matplotlib.pyplot as mtplt
# Loading the image
image = mh.imread('sun.png')
# Converting it to grayscale
image = mh.colors.rgb2gray(image)
# Getting the SURF dense points
surf_dense = surf.dense(image, 120)
# Creating a figure and axes for subplots
fig, axes = mtplt.subplots(1, 2)
# Displaying the original image
axes[0].imshow(image)
axes[0].set_title('Original Image')
axes[0].set_axis_off()
# Displaying the surf dense points
axes[1].imshow(surf_dense)
axes[1].set_title('SURF Dense Point')
axes[1].set_axis_off()
# Adjusting spacing between subplots
mtplt.tight_layout()
# Showing the figures
mtplt.show()

以下是上面代码的输出: -

Following is the output of the above code −

surf dense points

By Adjusting the Scale

我们可以调整比例尺以在不同的空间计算 SURF 稠密点的描述符。比例尺决定了在兴趣点周围检查的区域大小。

We can adjust the scale to compute the descriptors of SURF dense points at different spaces. The scale determines the size of the region that is examined around an interest point.

较小的比例尺适用于捕捉局部细节,而较大的比例尺适用于捕捉全局细节。

Smaller scales are good for capturing local details while larger scales are good for capturing global details.

在 mahotas 中,surf.dense() 函数的 scale 参数决定了在计算 SURF 稠密点的描述符时使用的比例尺。

In mahotas, the scale parameter of the surf.dense() function determines the scaling used when computing the descriptors of SURF dense points.

我们可以将任何值传递给该参数,以检查比例尺对 SURF 稠密点的影响。

We can pass any value to this parameter to check the impact of scaling on SURF dense points.

Example

在下面提到的示例中,我们正在调整比例尺以计算 SURF 稠密点的描述符:

In the example mentioned below, we are adjusting the scale to compute descriptors of SURF dense points −

import mahotas as mh
from mahotas.features import surf
import numpy as np
import matplotlib.pyplot as mtplt
# Loading the image
image = mh.imread('nature.jpeg')
# Converting it to grayscale
image = mh.colors.rgb2gray(image)
# Getting the SURF dense points
surf_dense = surf.dense(image, 100, np.sqrt(25))
# Creating a figure and axes for subplots
fig, axes = mtplt.subplots(1, 2)
# Displaying the original image
axes[0].imshow(image)
axes[0].set_title('Original Image')
axes[0].set_axis_off()
# Displaying the surf dense points
axes[1].imshow(surf_dense)
axes[1].set_title('SURF Dense Point')
axes[1].set_axis_off()
# Adjusting spacing between subplots
mtplt.tight_layout()
# Showing the figures
mtplt.show()

上述代码的输出如下:

Output of the above code is as follows −

scale adjusting

By Including Interest Points

我们在计算 SURF 稠密点的描述符时还可以包含图像的兴趣点。兴趣点是像素强度值显着变化的区域。

We can also include interest points of an image when computing the descriptors of SURF dense points. Interest points are areas where the intensity value of pixels' changes significantly.

在 mahotas 中,要在计算 SURF 稠密点的描述符时包含图像的兴趣点,我们可以将 include_interest_point 参数设置为布尔值“True”。

In mahotas, to include interest points of an image, we can set the include_interest_point parameter to the boolean value 'True', when computing the descriptors of SURF dense points.

Example

在这里,我们在计算图像的 SURF 稠密点的描述符时包含兴趣点。

In here, we are including interest points when computing the descriptors of SURF dense points of an image.

import mahotas as mh
from mahotas.features import surf
import numpy as np
import matplotlib.pyplot as mtplt
# Loading the image
image = mh.imread('tree.tiff')
# Converting it to grayscale
image = mh.colors.rgb2gray(image)
# Getting the SURF dense points
surf_dense = surf.dense(image, 100, include_interest_point=True)
# Creating a figure and axes for subplots
fig, axes = mtplt.subplots(1, 2)
# Displaying the original image
axes[0].imshow(image)
axes[0].set_title('Original Image')
axes[0].set_axis_off()
# Displaying the surf dense points
axes[1].imshow(surf_dense)
axes[1].set_title('SURF Dense Point')
axes[1].set_axis_off()
# Adjusting spacing between subplots
mtplt.tight_layout()
# Showing the figures
mtplt.show()

执行上面的代码后,我们得到以下输出: -

After executing the above code, we get the following output −

include interest points