function H = HOGFunc(I, cell_size, block_size,n_bins)
% COMPUTE_HOG Computes the HOG descriptor of the given image computed
% with the specified paramters.
%
% INPUT:
% I: image to extract HOGs
% cell_size: size of the cells in pixels
% block_size: size of the blocks in cells
% n_bins: number of bins of the histograms
%
% OUTPUT:
% H: HoG descriptor in a column vector form.
%
%
%$ Author Jose Marcos Rodriguez $
%$ Date: 2013/20/08 22:00:00 $
%$ Revision: 1.1 $
%% Setting gradient configuration
% gradient angle range control
epsilon = 0.0001;
L_norm = 2;
desp = 1;
total_angles = 180.0;
bin_width = total_angles/n_bins;
%% column matrix for mapping indices to bin center values
bin_centers_map = (bin_width/2:bin_width:total_angles)';
%% Compute the gradient in polar coordinates
[angles, magnitudes] = compute_gradient(I);
%% Split the gradient in cells
cell_coords = compute_cell_coordinates(angles,cell_size,cell_size,false);
%% initialize 3 dimensional matrix to hold all the histograms
% number of vertical and horizontal cells
[height,width] = size(I(:,:,1));
n_v_cells = floor(height/cell_size);
n_h_cells = floor(width/cell_size);
% init the histograms 3D matrix (7x14x9)
histograms = zeros(n_v_cells,n_h_cells,n_bins);
% ================================================
%% Computing histograms for all image cells
% ================================================
for index=1:size(cell_coords,2)
% current cell histogram initialization
h = zeros(1,n_bins);
% cell coords
x_min = cell_coords(1,index);
x_max = cell_coords(2,index);
y_min = cell_coords(3,index);
y_max = cell_coords(4,index);
% retrieve angles and magnitudes for all the pixels in the
% cell and conversion to degrees.
angs = angles(y_min:y_max,x_min:x_max);
angs = angs.*180/pi;
mags = magnitudes(y_min:y_max,x_min:x_max);
% indices for the left and right histogram bins that bound
% the current angle value for all the pixels in the cell
left_indices = round(angs/bin_width);
right_indices = left_indices+1;
% wraping contributions over the histogram boundaries.
left_indices(left_indices==0) = 9;
right_indices(right_indices==10) = 1;
% retrieving the left bin center value.
left_bin_centers = bin_centers_map(left_indices);
angs(angs < left_bin_centers) = ...
total_angles + angs(angs < left_bin_centers);
% calculating the contribution to both bins sides (vote weight)
% (matrices with same size as the cell)
right_contributions = (angs-left_bin_centers)/bin_width;
left_contributions = 1 - right_contributions;
left_contributions = mags.*left_contributions;
right_contributions = mags.*right_contributions;
% computing contributions for the current histogram bin by bin.
for bin=1:n_bins
% pixels that contribute to the bin with its left portion
pixels_to_left = (left_indices == bin);
h(bin) = h(bin) + sum(left_contributions(pixels_to_left));
% pixels that contribute to the bin with its right portion
pixels_to_right = (right_indices == bin);
h(bin) = h(bin) + sum(right_contributions(pixels_to_right));
end
% appending current hist. to the histograms matrix
row_offset = floor(index/n_h_cells + 1);
column_offset = mod(index-1,n_h_cells)+1;
histograms(row_offset,column_offset,:) = h(1,:);
end
% ================================================
%% block normalization (L2 norm)
% ================================================
hist_size = block_size*block_size*n_bins;
descriptor_size = hist_size*(n_v_cells-block_size+desp)*(n_h_cells-block_size+desp);
H = zeros(descriptor_size, 1);
col = 1;
row = 1;
% H = [];
%% Split the histogram matrix in blocks (this code assumes an 50% of overlap as desp is hard coded as 1)
while row <= n_v_cells-block_size+1
while col <= n_h_cells-block_size+1
% Getting all the histograms for a block
blockHists = ...
histograms(row:row+block_size-1, col:col+block_size-1, :);
% Getting the magnitude of the histograms of the block
magnitude = norm(blockHists(:),L_norm);
% Divide all of the histogram values by the magnitude to normalize
% them.
normalized = blockHists / (magnitude + epsilon);
% H = [H; normalized(:)];
offset = (row-1)*(n_h_cells-block_size+1)+col;
ini = (offset-1)*hist_size+1;
fin = offset*hist_size;
H(ini:fin,1) = normalized(:);
col = col+desp;
end
row = row+desp;
col = 1;
end
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
lecture5_for_students.rar_eastpeo_matlab_teachphv_人脸识别_机器视觉 (2000个子文件)
SVM_face_recognize_train.asv 2KB
lbpfeaturevector.asv 557B
LBPFunc.asv 456B
p (252).jpg 2KB
p (39).jpg 2KB
p (509).jpg 2KB
p (677).jpg 2KB
p (295).jpg 2KB
p (26).jpg 2KB
p (43).jpg 2KB
p (723).jpg 2KB
p (462).jpg 2KB
p (208).jpg 2KB
p (850).jpg 2KB
p (612).jpg 2KB
p (919).jpg 2KB
p (133).jpg 2KB
p (51).jpg 2KB
p (470).jpg 2KB
p (6).jpg 2KB
p (904).jpg 2KB
p (750).jpg 2KB
p (319).jpg 2KB
p (912).jpg 2KB
p (909).jpg 2KB
p (965).jpg 2KB
p (895).jpg 2KB
p (584).jpg 2KB
p (938).jpg 2KB
p (84).jpg 2KB
p (791).jpg 2KB
p (415).jpg 2KB
p (73).jpg 2KB
p (259).jpg 2KB
p (6).jpg 2KB
p (502).jpg 2KB
p (432).jpg 2KB
p (347).jpg 2KB
p (581).jpg 2KB
p (608).jpg 2KB
p (991).jpg 2KB
p (61).jpg 2KB
p (236).jpg 2KB
p (921).jpg 2KB
p (271).jpg 2KB
p (931).jpg 2KB
p (24).jpg 2KB
p (141).jpg 2KB
p (692).jpg 2KB
p (395).jpg 2KB
p (745).jpg 2KB
p (452).jpg 2KB
p (79).jpg 2KB
p (260).jpg 2KB
p (396).jpg 2KB
p (955).jpg 2KB
p (760).jpg 2KB
p (797).jpg 2KB
p (899).jpg 2KB
p (441).jpg 2KB
p (855).jpg 2KB
p (64).jpg 2KB
p (371).jpg 2KB
p (607).jpg 2KB
p (229).jpg 2KB
p (924).jpg 2KB
p (431).jpg 2KB
p (871).jpg 2KB
p (219).jpg 2KB
p (826).jpg 2KB
p (457).jpg 2KB
p (682).jpg 2KB
p (477).jpg 2KB
p (917).jpg 2KB
p (87).jpg 2KB
p (698).jpg 2KB
p (525).jpg 2KB
p (325).jpg 2KB
p (932).jpg 2KB
p (600).jpg 2KB
p (695).jpg 2KB
p (218).jpg 2KB
p (196).jpg 2KB
p (667).jpg 2KB
p (43).jpg 2KB
p (392).jpg 2KB
p (386).jpg 2KB
p (961).jpg 2KB
p (733).jpg 2KB
p (954).jpg 2KB
p (967).jpg 2KB
p (929).jpg 2KB
p (21).jpg 2KB
p (710).jpg 2KB
p (834).jpg 2KB
p (790).jpg 2KB
p (708).jpg 2KB
p (847).jpg 2KB
p (400).jpg 2KB
p (487).jpg 2KB
共 2000 条
- 1
- 2
- 3
- 4
- 5
- 6
- 20
资源评论
weixin_42651887
- 粉丝: 80
- 资源: 1万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功