目标检测学习记录——特征提取之HOG

本文详细介绍了计算机视觉中的HOG(Histogram of Oriented Gradient)特征提取方法,包括图像预处理、梯度计算、细胞单元定义、直方图构建、块滑动与归一化等步骤,及其在行人检测中的应用。通过学习,可以深入理解HOG特征在目标检测中的重要作用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

===================================================================================================================

          作为一名计算机视觉研究和代码编程上的小菜鸟。上学期就看了Histogram of Oriented Gradient for Human Detection 整篇论文不长,看了似乎也懂,但是回过头来感觉懂得其实很浅显。在此开博,记录学习的知识,也算是记录自己研究生的历程。没有新的见解,更多的是个人对此理解的整理。

==========================================================================================================================================================

     简述:方向梯度直方图(Histogram of Oriented Gradient, HOG)特征是一种在计算机视觉和图像处理中用来进行物体检测的特征描述子(用于表示特征)。它通过计算和统计图像局部区域的梯度方向直方图来构成特征。Hog特征结合SVM分类器已经被广泛应用于图像识别中,尤其在行人检测中获得了极大的成功。需要提醒的是,HOG+SVM进行行人检测的方法是法国研究人员Dalal2005CVPR上提出的,而如今虽然有很多行人检测算法不断提出,但基本都是以HOG+SVM的思路为主。

     大概过程:

       HOG特征提取方法就是将一个image(你要检测的目标或者扫描窗口):

       1)灰度化(将图像看做一个x,y,z(灰度)的三维图像);

       2)采用Gamma校正法对输入图像进行颜色空间的标准化(归一化);目的是调节图像的对比度,降低图像局部的阴影和光照变化所造成的影响,同时可以抑制噪音的干扰;

       3)计算图像每个像素的梯度(包括大小和方向);主要是为了捕获轮廓信息,同时进一步弱化光照的干扰。

       4)将图像划分成小cells(例如6*6像素/cell);

        5)统计每个cell的梯度直方图(不同梯度的个数),即可形成每个celldescriptor

       6)将每几个cell组成一个block(例如3*3cell/block),一个block内所有cell的特征descriptor串联起来便得到该blockHOG特征descriptor

        7)将图像image内的所有blockHOG特征descriptor串联起来就可以得到该image(你要检测的目标)的HOG特征descriptor了。这个就是最终的可供分类使用的特征向量了。





      理解:将图像灰度化后,将图像分成小的连通区域称为细胞单元(cell),采集得到像素点的梯度或边缘的方向直方图(Histogram of Oriented Gradient)。文章中检测窗口取128*64,区块(block)取16*16,每个Block划分成2*2的cell,细胞单元(cell)取8*8,移动窗口步长为8个像素。所以一个检测窗口分为[(128-16)/8+1]*[(64-16)/8+1]=15*7=105个block块。每个块分为4个cell,每个cell分成9个bin,所以HOG特征描述子有105*4*9=3780维。


                               block分成cell



                                                    cell按方向分成9个bin

还未了解的点:

         三线插值?


Matlab源码:见TimeHandle的blog

转自:http://www.zhizhihu.com/html/y2010/1690.html

Histograms of Oriented Gradients (HOG)特征 MATLAB 计算

[plain]  view plain copy
  1. function F = hogcalculator(img, cellpw, cellph, nblockw, nblockh,...  
  2. nthet, overlap, isglobalinterpolate, issigned, normmethod)  
  3. % HOGCALCULATOR calculate R-HOG feature vector of an input image using the  
  4. % procedure presented in Dalal and Triggs's paper in CVPR 2005.  
  5. %  
  6. % Author: timeHandle  
  7. % Time: March 24, 2010  
  8. % May 12,2010 update.  
  9. %  
  10. % this copy of code is written for my personal interest, which is an   
  11. % original and inornate realization of [Dalal CVPR2005]'s algorithm  
  12. % without any optimization. I just want to check whether I understand  
  13. % the algorithm really or not, and also do some practices for knowing  
  14. % matlab programming more well because I could be called as 'novice'.   
  15. % OpenCV 2.0 has realized Dalal's HOG algorithm which runs faster  
  16. % than mine without any doubt, ╮(╯▽╰)╭ . Ronan pointed a error in   
  17. % the code,thanks for his correction. Note that at the end of this  
  18. % code, there are some demonstration code,please remove in your work.  
  19.   
  20. %   
  21. % F = hogcalculator(img, cellpw, cellph, nblockw, nblockh,  
  22. % nthet, overlap, isglobalinterpolate, issigned, normmethod)  
  23. %  
  24. % IMG:  
  25. % IMG is the input image.  
  26. %  
  27. % CELLPW, CELLPH:  
  28. % CELLPW and CELLPH are cell's pixel width and height respectively.  
  29. %  
  30. % NBLOCKW, NBLCOKH:  
  31. % NBLOCKW and NBLCOKH are block size counted by cells number in x and  
  32. % y directions respectively.  
  33. %  
  34. % NTHET, ISSIGNED:  
  35. % NTHET is the number of the bins of the histogram of oriented  
  36. % gradient. The histogram of oriented gradient ranges from 0 to pi in  
  37. % 'unsigned' condition while to 2*pi in 'signed' condition, which can  
  38. % be specified through setting the value of the variable ISSIGNED by  
  39. % the string 'unsigned' or 'signed'.  
  40. %  
  41. % OVERLAP:  
  42. % OVERLAP is the overlap proportion of two neighboring block.  
  43. %  
  44. % ISGLOBALINTERPOLATE:  
  45. % ISGLOBALINTERPOLATE specifies whether the trilinear interpolation  
  46. % is done in a single global 3d histogram of the whole detecting  
  47. % window by the string 'globalinterpolate' or in each local 3d  
  48. % histogram corresponding to respective blocks by the string  
  49. % 'localinterpolate' which is in strict accordance with the procedure  
  50. % proposed in Dalal's paper. Interpolating in the whole detecting  
  51. % window requires the block's sliding step to be an integral multiple  
### 图像特征提取中的像素区间确定 在图像特征提取过程中,定义用于特征提取的像素区间对于提高算法性能至关重要。通常情况下,这一过程依赖于特定的应用场景以及所采用的具体方法。 #### 基本概念 积分图是一种有效工具,在遍历一次图像的情况下可以求得图像中所有区域像素和,从而大大提升图像特征计算效率[^2]。通过构建积分图,可以在后续操作中迅速获取任意矩形区域内像素总和,这对于设定固定大小窗口来评估局部特性非常有用。 #### 确定像素区间的策略 为了有效地进行特征检测,往往先执行海选步骤:当某个像素与其邻近大多数像素存在显著差异时,则将其视为潜在的兴趣点或边缘位置[^4]。接着进入精选阶段——针对那些紧密相连形成簇状结构的关键点群组,挑选出最具代表性的单一点位作为最终选定的结果。 具体到像素区间的界定上: - **基于尺度空间理论**的方法会考虑多分辨率下的响应强度变化情况,自动适应不同尺寸的目标对象; - 对于一些预设形状(如圆形、方形)的模板匹配任务而言,可以直接指定相应范围内的坐标偏移量; - 利用机器学习模型训练得到的概率分布函数指导选取合适的采样框边界也是常见做法之一。 下面给出一段简单的MATLAB代码片段展示如何利用滑动窗技术实现自定义宽度高度的感兴趣区域(ROI)扫描: ```matlab function [keypoints, descriptors] = extractFeatures(image, windowSize) % image: 输入灰度图片矩阵 % windowSize: 定义为[N M], 表示N行M列的矩形窗口 imageSize = size(image); keypoints = []; descriptors = []; for i = 1:imageSize(1)-windowSize(1)+1 for j = 1:imageSize(2)-windowSize(2)+1 region = image(i:i+windowSize(1)-1,j:j+windowSize(2)-1); % 这里可以根据region的内容进一步处理, % 比如计算HOG描述子或者其他类型的特征向量 % 将当前窗口中心点加入关键点列表 keypoints(end+1,:) = [i+(windowSize(1)/2),j+(windowSize(2)/2)]; % 记录下对应的描述符 descriptor = computeDescriptor(region); %#ok<UNRCH> descriptors(:,end+1) = descriptor; end end end ``` 此段代码展示了怎样在一个给定输入图像内按照预定参数`windowSize`移动一个小窗口,并从中抽取感兴趣的特征信息。需要注意的是实际应用中还需结合具体的上下文环境调整细节部分的设计思路。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值