function H = getHistogram(magnitudes, angles, numBins)
% GETHISTOGRAM Computes a histogram for the supplied gradient vectors.
% H = getHistogram(magnitudes, angles, numBins)
%
% This function takes the supplied gradient vectors and places them into a
% histogram with 'numBins' based on their unsigned orientation.
%
% "Unsigned" orientation means that, for example, a vector with angle
% -3/4 * pi will be treated the same as a vector with angle 1/4 * pi.
%
% Each gradient vector's contribution is split between the two nearest bins,
% in proportion to the distance between the two nearest bin centers.
%
% A gradient's contribution to the histogram is equal to its magnitude;
% the magnitude is divided between the two nearest bin centers.
%
% Parameters:
% magnitudes - A column vector storing the magnitudes of the gradient
% vectors.
% angles - A column vector storing the angles in radians of the
% gradient vectors (ranging from -pi to pi)
% numBins - The number of bins to place the gradients into.
% Returns:
% A row vector of length 'numBins' containing the histogram.
% $Author: ChrisMcCormick $ $Date: 2013/12/04 22:00:00 $ $Revision: 1.2 $
% Revision Notes:
% v1.2
% - Expanded '+=' since this gave Matlab users trouble.
% v1.1
% - The function was actually hardcoded to 9 bins; it now properly supports
% specifying 'numBins'.
% - It now returns an unsigned histogram. This has been shown to improve
% accuracy for person detection.
% Compute the bin size in radians. 180 degress = pi.
binSize = pi / numBins;
% The angle values will range from 0 to pi.
minAngle = 0;
% Make the angles unsigned by adding pi (180 degrees) to all negative angles.
angles(angles < 0) = angles(angles < 0) + pi;
% The gradient angle for each pixel will fall between two bin centers.
% For each pixel, we split the bin contributions between the bin to the left
% and the bin to the right based on how far the angle is from the bin centers.
% For each pixel's gradient vector, determine the indeces of the bins to the
% left and right of the vector's angle.
%
% The histogram needs to wrap around at the edges--vectors on the far edges of
% the histogram (i.e., close to -pi or pi) will contribute partly to the bin
% at that edge, and partly to the bin on the other end of the histogram.
% For vectors with an orientation close to 0 radians, leftBinIndex will be 0.
% Likewise, for vectors with an orientation close to pi radians, rightBinIndex
% will be numBins + 1. We will fix these indeces after we calculate the bin
% contribution amounts.
leftBinIndex = round((angles - minAngle) / binSize);
rightBinIndex = leftBinIndex + 1;
% For each pixel, compute the center of the bin to the left.
leftBinCenter = ((leftBinIndex - 0.5) * binSize) - minAngle;
% For each pixel, compute the fraction of the magnitude
% to contribute to each bin.
rightPortions = angles - leftBinCenter;
leftPortions = binSize - rightPortions;
rightPortions = rightPortions / binSize;
leftPortions = leftPortions / binSize;
% Before using the bin indeces, we need to fix the '0' and '10' values.
% Recall that the histogram needs to wrap around at the edges--bin "0"
% contributions, for example, really belong in bin 9.
% Replace index 0 with 9 and index 10 with 1.
leftBinIndex(leftBinIndex == 0) = numBins;
rightBinIndex(rightBinIndex == (numBins + 1)) = 1;
% Create an empty row vector for the histogram.
H = zeros(1, numBins);
% For each bin index...
for (i = 1:numBins)
% Find the pixels with left bin == i
pixels = (leftBinIndex == i);
% For each of the selected pixels, add the gradient magnitude to bin 'i',
% weighted by the 'leftPortion' for that pixel.
H(1, i) = H(1, i) + sum(leftPortions(pixels)' * magnitudes(pixels));
% Find the pixels with right bin == i
pixels = (rightBinIndex == i);
% For each of the selected pixels, add the gradient magnitude to bin 'i',
% weighted by the 'rightPortion' for that pixel.
H(1, i) = H(1, i) + sum(rightPortions(pixels)' * magnitudes(pixels));
end
end
阿里matlab建模师
- 粉丝: 4780
- 资源: 2880
最新资源
- 基于labview的图像透明算法 1 将某个水印图片以透明度可调的方式插入另外一张大图 2 水印图片角度大小都可调整 3 纯labview代码
- Linux安全应急响应之日志分析
- 三菱FX3U与3台施耐德ATV12变频器通讯程序三菱FX3U与3台施耐德ATV12变频器通讯案例程序,有注释 并附送程序,有接线方式,设置 同时解决施耐德ATV变频器断电重启后,自准备工作,程序稳
- python基于机器学习SVM、KNN、决策树、朴素贝叶斯等算法数据分析案例(心脏病、癌症、糖尿病预测、数据分析等)集合源码+详细注释.zip
- l3-024 oriol和david 解题思路
- Mongodb客户端~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- 练习题(1.16).doc
- 7_base.apk.1
- stm32f103的Bootloader IAP串口升级stm32固件的资料,支持ymodem协议,aes256通信字段加密技术方案和学习资料,成熟产品方案已经用在批量产品上,资料包括上位机(电脑端)
- 解决Keil uVision5使用ST-LINK调试时软件闪退问题
- 基于微信小程序的后疫情时代高校宿舍管理系统小程序答辩PPT.pptx
- 基于微信小程序的高校报修与互助平台小程序答辩PPT.pptx
- 基于微信小程序的供货服务平台小程序答辩PPT.pptx
- 基于微信小程序的社区养老保险系统小程序答辩PPT.pptx
- 基于微信小程序的私家车位共享系统小程序答辩PPT.pptx
- 基于微信小程序的酒店管理系统小程序答辩PPT.pptx
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
- 1
- 2
前往页