%% [Pori05] F. Porikli: "Integral histogram: a fast way to extract histogram
% features", Proc. IEEE CVPR, pp. 829?836, 2005.%
%% [PT06] F. Porikli and O. Tuzel: "Fast construction of covariance matrices
% for arbitrary size image windows", Proc. IEEE ICIP, 2006.%
%% [OPENVIDIA]
%%% Credit
% (ISR-2/LANL)%
%% See also% Ressembles:
% ,% .
% Requires:% .
%% Function implementation
function [IH, I] = integralhisto1d(I, nbin, bound)
[X,Y] = size(I(:,:,1));
if nargin==3, imax = bound(2); imin = bound(1);
else imax = max(I(:)); imin = min(I(:));
if nargin<2 nbin = round(imax - imin) + 1;
endend
if imax==imin,
error('integralhisto1d:inputerror', 'constant image - nothing to do');elseif nbin==0
nbin = round(imax - imin) + 1; % again, defaultend
if nbin>0
% quantize the input imageI = floor((nbin-1) * (I - imin) / (imax - imin));
else nbin = abs(nbin); % a way not to quantize
end
% method 1: optimized, fully vectorial (non sparse) calculation and % representation of integral histograms
IH = zeros(X, Y, nbin);
ind = (1:X*Y)';
IH(ind + X*Y*I(:)) = 1;
% IH = cumsum(cumsum(IH,2),1);IH = integralimage(IH);
if false
IH = sparse(reshape(IH, [X*Y, nbin])); %#ok end
% % method 2: non vectorial version
% subind = nbin * (0:Y-1);% % create the output histograms
% IH = zeros( X+1, Y, nbin );% % propagate the histogram along x-dimension
% for x=1:X% % method 2.a)
% H = zeros(nbin,Y);% hh = I(x,:) + subind + 1;
% H(hh) = H(hh) + 1; % % cumulate the histogram along y-dimension
% H = cumsum(H,2)';% % propagate
% IH(x+1,:,:) = H + squeeze(IH(x,:,:));%
% % method 2.b)% % H = zeros(nbin,1);
% % for y=1:Y% % H(I(x,y) + 1) = H(I(x,y) + 1) + 1;
% % IH(x+1,y,:) = H + squeeze(IH(x,y,:));% % end
% end% % get rid of the dummy row
% IH = IH(2:end,:,:);
end % end of integralhisto1d
##### SOURCE END #####-->