getpatchhist.m

来自「neural network falut finding」· M 代码 · 共 29 行

M
29 行
字号
%
% Input = image (HxWxD)
% e.g. 
%   im = double(imread('test.jpg')); % Read in image 256x256x3
%   % compute 16x16x16 colour histogram of the image
%   h = getPatchHist(im, 16);
%   
% Output = 1D histogram vector, h
%
%   size(h) ==> (bins^D)x(1)
function h = getPatchHist(clip, bins)

if (nargin <= 1)
   bins = 8;
end


z = size(clip,3);
clip2 = zeros(size(clip,1),size(clip,2));

f = 1;
for i = 1:z
   clip2 = clip2 + f*floor(clip(:,:,i)*bins/256);
   f=f*bins;
end

h = hist(makelinear(clip2), 0:(f-1));
h = h / sum(h);

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?