LBPH-matlab
LBPH,Local Binary Patterns Histograms,即LBP特征的统计直方图,LBPH将LBP特征与图像的空间信息结合在一起。这种表示方法由Ahonen等人在论文[3]中提出,他们将LBP特征图像分成m个局部块,并提取每个局部块的直方图,然后将这些直方图依次连接在一起形成LBP特征的统计直方图,即LBPH。
一幅图像具体的计算LBPH的过程:
- 计算图像的LBP特征图像。
- 将LBP特征图像进行分块,Opencv中默认将LBP特征图像分成8行8列64块区域
- 计算每块区域特征图像的直方图cell_LBPH,将直方图进行归一化,直方图大小为1*numPatterns
- 将上面计算的每块区域特征图像的直方图按分块的空间顺序依次排列成一行,形成LBP特征向量,大小为1*(numPatterns*64)
- 用机器学习的方法对LBP特征向量进行训练,用来检测和识别目标
举例说明LBPH的维度:
采样点为8个,如果用的是原始的LBP或Extended LBP特征,其LBP特征值的模式为256种,则一幅图像的LBP特征向量维度为:64*256=16384维,而如果使用的UniformPatternLBP特征,其LBP值的模式为59种,其特征向量维度为:64*59=3776维,可以看出,使用等价模式特征,其特征向量的维度大大减少,这意味着使用机器学习方法进行学习的时间将大大减少,而性能上没有受到很大影响。
function result = getLBPH(img, numPatterns, grid_x, grid_y)
[rows, cols] = size(img);
width = floor(cols / grid_x);
height = floor(rows / grid_y);
result = zeros(grid_x * grid_y, numPatterns);
if size(img) == 0
return;
end
resultRowIndex = 1;
for i=0:grid_x-1
for j=0:grid_y-1
cell = img(i*height+1:(i+1)*height, j*width+1:(j+1)*width);
hist_cell = getLocalRegionLBPH(cell, 0, numPatterns-1, true);
result(resultRowIndex, 1:numPatterns) = hist_cell;
resultRowIndex = resultRowIndex + 1;
end
end
result = reshape(result, [1 grid_x*grid_y*numPatterns]);
end
function result = getLocalRegionLBPH(src, minValue, maxValue, normed)
edges = [minValue minValue+1:1:maxValue maxValue];
hist = histogram(src, edges);
result = hist.Values;
if normed
result = mapminmax(result, 0, 1);
end
result = reshape(result, [1, maxValue-minValue+1]);
end

浙公网安备 33010602011771号