加速的健壮特征¶
在 0.8 版本加入: 在0.8版中,一些内部函数现在位于mahotas.Features.surf中,而不是mahotas.surf中
Speeded-Up Robust Features (SURF) 是一项最新的创新, local features 一家人。该算法分为两个步骤:
兴趣点检测。
兴趣点描述。
该功能 mahotas.features.surf.surf
结合了两个步骤::
import numpy as np
from mahotas.features import surf
f = ... # input image
spoints = surf.surf(f)
print("Nr points: {}".format(len(spoints)))
在给定结果的情况下,我们可以执行简单的集群,例如, ` scikit-learn **
try:
from sklearn.cluster import KMeans
# spoints includes both the detection information (such as the position
# and the scale) as well as the descriptor (i.e., what the area around
# the point looks like). We only want to use the descriptor for
# clustering. The descriptor starts at position 5:
descrs = spoints[:,5:]
# We use 5 colours just because if it was much larger, then the colours
# would look too similar in the output.
k = 5
values = KMeans(n_clusters=k).fit(descrs).labels_
colors = np.array([(255-52*i,25+52*i,37**i % 101) for i in range(k)])
except:
values = np.zeros(100)
colors = [(255,0,0)]
所以我们给每个可能的颜色分配了不同的颜色
帮助者 surf.show_surf
在兴趣点周围绘制彩色多边形::
f2 = surf.show_surf(f, spoints[:100], values, colors)
imshow(f2)
show()
在《毛霍塔斯》的作者路易斯·佩德罗的一张照片上运行以上内容:
from __future__ import print_function
import numpy as np
import mahotas as mh
from mahotas.features import surf
from matplotlib import pyplot as plt
f = mh.demos.load('luispedro', as_grey=True)
f = f.astype(np.uint8)
spoints = surf.surf(f, 4, 6, 2)
print("Nr points:", len(spoints))
try:
from sklearn.cluster import KMeans
descrs = spoints[:,5:]
k = 5
values = KMeans(n_clusters=k).fit(descrs).labels_
colors = np.array([(255-52*i,25+52*i,37**i % 101) for i in range(k)])
except:
values = np.zeros(100, int)
colors = np.array([(255,0,0)])
f2 = surf.show_surf(f, spoints[:100], values, colors)
fig,ax = plt.subplots()
ax.imshow(f2)
fig.show()
(Source code
, png
, hires.png
, pdf
)

API文档¶
这个 mahotas.features.surf
模块包含SURF管道中所有步骤的单独函数。
- mahotas.features.surf.dense(f, spacing, scale={np.sqrt(spacing)}, is_integral=False, include_interest_point=False)
DESC_ARRAY=密集(f,间距,比例={np.sqrt(间距)},IS_INTEGRATION=FALSE,INCLUDE_INTERECT_POINT=FALSE)
- 参数:
- f图像
原始图像
- spacing整数
点之间的距离
- scale浮动,可选
兴趣点的比例。默认情况下,它设置为
np.sqrt(spacing)
- is_integral布尔型,可选
是否 f 是一个完整的形象
- include_interest_point布尔值,可选
是否返回利息点信息。缺省值为False
- 退货:
- descriptorsNdarray
密集点处的描述符。请注意,兴趣点是 not returned by default 。
参见
surf
函数查找兴趣点,然后计算描述符
descriptors
函数在用户提供的兴趣点计算描述符
- mahotas.features.surf.integral(f, in_place=False, dtype=<class 'numpy.float64'>)
Fi=整型(f,in_place=FALSE,dtype=np.double):
计算积分图像
- 参数:
- fNdarray
输入图像。仅支持2-D图像。
- in_place布尔值,可选
是否覆盖 f (默认值:FALSE)。
- dtype数据类型,可选
要使用的数据类型(默认:双精度)
- 退货:
- fi :ndarray of dtype 与…形状相同 fNdarray of
整体形象
- mahotas.features.surf.surf(f, nr_octaves=4, nr_scales=6, initial_step_size=1, threshold=0.1, max_points=1024, descriptor_only=False)
Points=SURF(f,nr_octaves=4,nr_scales=6,初始步骤大小=1,Threshold=0.1,max_Points=1024,Descriptor_Only=False):
运行冲浪检测和描述符计算
加速稳健特征(SURF)是在自动确定的关键点上计算的快速局部特征。
- 参数:
- fNdarray
输入图像
- nr_octaves整型,可选
八度音阶的NR(默认:4)
- nr_scales整型,可选
比例尺的NR(默认:6)
- initial_step_size整型,可选
初始步长(以像素为单位)(默认值:1)
- threshold浮动,可选
兴趣点强度阈值(默认为0.1)
- max_points整型,可选
要返回的最大点数。默认情况下,最多返回1024点。请注意,即使在有那么多点的情况下,数字也可能更小。这是实现阈值的方式的副作用:仅
max_points
是被考虑的,但其中一些可能会被过滤掉。- descriptor_only布尔型,可选
如果
descriptor_only
,然后仅返回64个元素的描述符(缺省为False
)。
- 退货:
- points双重线,形状=(N,6+64)
N 是分数的nr。每个点都表示为 (y,x,scale,score,laplacian,angle, D_0,...,D_63) 哪里 y,x,scale 就是这个位置, angle 迎新, score 和 laplacian 探测器的分数和标志;以及 D_i 是描述符
如果
descriptor_only
,那么只有 D_i S返回,数组具有形状(N,64)!
参考文献
赫伯特·贝,Andreas Ess,Tinne Tuytelaars,Luc Van Gool《冲浪:加速的稳健特征》,计算机视觉和图像理解(CVIU),第110卷,第3期,第346-359页,2008