% RES = BandHShowHists(image1, image2)
% 
% Plots the histograms for each band and level of the steerable pyramid
%
% Copyright Paul Viola, 6/97

function BandHShowHists(im, res)

% Initialize the filters

filts = 'sp5Filters';
[lo0filt,hi0filt,lofilt,bfilts,steermtx,harmonics] = eval(filts);
fsz = round(sqrt(size(bfilts,1))); fsz =  [fsz fsz];
nfilts = size(bfilts,2);
nrows = floor(sqrt(nfilts));
nbins = 100;

%% build the intial Steerable pyramid:

nlevels = maxPyrHt(size(im),size(lofilt));
[N,X] = histo(im(:),nbins);

[ipyr,ipind] = buildSpyr(im, nlevels, filts);
[rpyr,rpind] = buildSpyr(res, nlevels, filts);
nbands = spyrNumBands(ipind);

for level = 1:nlevels
  for band = 1:nbands
	rband = 1 + band + nbands*(level-1);
	target = ipyr(pyrBandIndices(ipind,rband));
	current = rpyr(pyrBandIndices(rpind,rband));
	[tmn, tmx] = range2(target);
	[cmn, cmx] = range2(current);
	[tN, tX] = histo(target, nbins/level);
	[cN, cX] = histo(current, nbins/level);
	subplot(1,2,1); plot(tX,tN); axis([tmn tmx 0 max(tN)]);
	subplot(1,2,2);  plot(cX,cN); axis([cmn cmx 0 max(cN)]);
	disp 'Hit return to show next histogram....'
	pause
      end
    end
