HOG特征

对HOG算法每一个步骤具体详细的介绍可参考:HOG特征——行人识别

对HOG算法的特点和思想的介绍可参考:目标检测的图像特征提取之(一)HOG特征

调用Python中的skimage库提取图像HOG特征的示例代码如下,代码摘自 图像特征工程 HOG特征描述子介绍

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
from skimage.io import imread, imshow
from skimage.transform import resize
from skimage.feature import hog
from skimage import exposure
import matplotlib.pyplot as plt
 
img = imread('lena.jpg')
resized_img = resize(img, (128, 64))
 
# 创建hog特征
fd, hog_image = hog(resized_img,
                    orientations=9,            # Number of orientation bins
                    pixels_per_cell=(8, 8),    # Size (in pixels) of a cell
                    cells_per_block=(2, 2),    # Number of cells in each block
                    block_norm='L2',           # Normalization using L2-norm
                    visualize=True,            # Return an image of the HOG
                    multichannel=True)
 
fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(16, 8), sharex=True, sharey=True)
ax1.imshow(resized_img, cmap=plt.cm.gray)
ax1.set_title('Input image')
# 缩放直方图以便更好地显示
hog_image_rescaled = exposure.rescale_intensity(hog_image, in_range=(0, 10))
ax2.imshow(hog_image_rescaled, cmap=plt.cm.gray)
ax2.set_title('HoG image')
plt.show()

运行结果:

程序中的fd就是输入图像的HOG特征向量,向量长度为3780. 这个数值的计算方法可参考本文第一行的链接。

 

posted @   Picassooo  阅读(446)  评论(0编辑  收藏  举报
编辑推荐:
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
阅读排行:
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 单元测试从入门到精通
点击右上角即可分享
微信分享提示