histogram difference

  • Follow


%
% 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);

can anyone explain me how the above code is working to calculate the histogram of a color image. just tell me wht the for loop is doing ? 
0
Reply kiran8049 5/11/2011 7:07:02 PM

It's basically concatenating the histograms of the 3 color channels
together into one 1D hist that is 3 times as long.  So clip2 will have
the red values in the range 0-15, the green values in the range 16-31,
and the blue values in the range 32 - 47.  Taking the hist will give
you a 1D histogram with values in the range 0-47 with the values
representing the color channels.

I don't see the use of doing it this way rather than the
straightforward intuitive way.
0
Reply imageanalyst (7590) 5/11/2011 9:00:59 PM


1 Replies
36 Views

(page loaded in 0.063 seconds)

Similiar Articles:













7/15/2012 4:47:05 PM


Reply: