% comparahist: compares histograms; S. Mann
% see also Contrast Limited Adaptive Histogram Specification (local stats...?)

frame1=13
frame2=16
%frame2=34 % frame 13 and 34 are the same exposure, straight line where certain
%frame2=37;

eval(sprintf('image1=loadpnm(''s%03d.pgm'');',frame1));
eval(sprintf('image2=loadpnm(''s%03d.pgm'');',frame2));

[M,N]=size(image1);
%image1=image1(:,1:N-25);
%image2=image2(:,1+25:N);
%image1=image1(:,1:N-50);
%image2=image2(:,1+50:N);

J=comparagram(image1,image2);
%Jl=J;
%Jl=sqrt(J); % sqrt() or log(()+1) usually improves results
myeps=.001;
Jl=log(J+myeps) - log(myeps); % make it be nonnegative

subplot(111)
clg

%J=comparagram(image1,image2);
%subplot(224);
tvs(-Jl.'); axis('xy'); axis('square');
title('COMPARAGRAM'); xlabel('f'); ylabel('g(f)');
%hold on
%plot(g); axis([0,255,0,255]); axis('square');
%hold off

