Matlab计算图像HOG特征
HOG特征
关于HOG特征,可以参见另一篇HOG特征。
方向梯度直方图(Histogram of Oriented Gradient, HOG)特征是一种在计算机视觉和图像处理中用来进行物体检测的特征描述子。它通过计算和统计图像局部区域的梯度方向直方图来构成特征。
VLFeat和Piotr’s Image & Video Matlab Toolbox
本文通过使用VLFeat和Piotr’s Image & Video Matlab Toolbox两种工具箱进行HOG特征计算。关于VLFeat和Piotr’s Image & Video Matlab Toolbox的配置安装,可参考VLFeat和Piotr’s Image & Video Matlab Toolbox。
VLFeat计算HOG特征
HOG特征的计算使用函数vl_hog
一个简单的例子:
原始图像为:
UoCTTI版本(默认)的计算hog特征matlab代码为:
I = single(imread('peppers.png'))/255; %读取图像并将数据类型转为single
cellSize = 8 ; %设置cell大小
hog = vl_hog(I, cellSize, 'verbose', 'variant', 'dalaltriggs') ; %计算hog特征
imhog = vl_hog('render', hog, 'verbose', 'variant', 'dalaltriggs') ; %将hog特征转化为图像
clf;figure(1);imagesc(I);
figure(2);imagesc(imhog);colormap gray;
UoCTTI版本的表示hog特征的图像为:
原始的Dalal-Trigg版本的计算hog特征matlab代码为:
% Dalal-Triggs variant
I = single(imread('peppers.png'))/255; %读取图像并将数据类型转为single
cellSize = 8 ; %设置cell大小
hog = vl_hog(I, cellSize, 'verbose', 'variant', 'dalaltriggs') ; %计算hog特征
imhog = vl_hog('render', hog, 'verbose', 'variant', 'dalaltriggs') ; %将hog特征转化为图像
clf;figure(1);imagesc(I);
figure(2);imagesc(imhog);colormap gray;
原始的Dalal-Trigg版本的表示hog特征的图像为:
可以看出,两种方法的差别并不明显。
具体对于两种实现方法的差异可以参考各自的资料。
格式说明
上述例子中,hog变量中存储的就是计算得到的hog特征的值。
原始图像的大小为384*512。
cellSize 的大小设置为8。
原始的Dalal-Trigg版本的hog特征个数为48*64*36。其中36表示hog特征维度。
Dalal-Triggs works instead with undirected gradients only and does not do any compression, for a total of 36 dimension.
Dalal-Trigg使用无方向梯度计算hog特征,并不做多余处理,所以hog特征有36维。(应该是bins的个数为36)
UoCTTI版本的hog特征为48/*64/*31,其中最后的31表示hog特征维度。关于UoCTTI版本的hog特征的说明为:
UoCTTI variant computes bot directed and undirected gradients as well as a four dimensional texture-energy feature, but projects the result down to 31 dimensions.
(应该是UoCTTI版本增添了一些特征,但最后选取了其中的31个?)
更多VLFeat计算hog特征的信息可以参考VLFeatw网站。
Video Matlab Toolbox计算HOG特征
Piotr’s Matlab Toolbox关于hog的页面是:Piotr’s Matlab Toolbox
在配置好Piotr’s Matlab Toolbox后,使用hog命令计算hog特征
USAGE:
H = hog( I, [binSize], [nOrients], [clip], [crop] )
INPUTS:
I - [hxw] color or grayscale input image (must have type single)
binSize - [8] spatial bin size
nOrients - [9] number of orientation bins
clip - [.2] value at which to clip histogram bins
crop - [0] if true crop boundaries
OUTPUTS:
H - [h/binSize w/binSize nOrients*4] computed hog features
例子:
I=imResample(single(imread('peppers.png')),[480 640])/255;
tic, for i=1:125, H=hog(I,8,9); end; toc % ~1s for 125 iterations
figure(1); im(I); V=hogDraw(H,25); figure(2); im(V)
其中一些命令为Piotr’s Matlab Toolbox自带的图像处理命令。
对于上例准中图像运行结果为
hog特征存储在H中,特征为36维。原始图像大小被调整为480*640,因此H为60*80*36
以上就是使用VLFeat和Piotr’s Image & Video Matlab Toolbox计算hog特征的方法。
关于三维hog特征
Reference