function test1
% Plot the likelihoods and edge pair cooccurrence
% probabilities of all possible edge pair geometries.
%
% Copyright (C) 2001-2009 Center for Perceptual Systems

% Generate geometries
%
% The plots can take a long time to generate.  Change N to a
% small integer like 2 or 4 to speed up plotting by a factor
% of N and make the plots sparser.
N=1;
[d,phi,thd]=ndgrid([0:15]*8+4,[0:71]*2*pi/72,[0:N:71]*2*pi/72);

% Read histogram
fn='kodak_counts_16_8_72_72.txt';
[same,diff]=readhist(fn,16,72,72);

% Create a table of distance dependent likelihoods
l=ddl(same,diff);

% Lookup values from the likelihood table
w=lookup(d,phi,thd,l,8);

% Clamp likelihoods to a range
w(find(w<0.01))=0.01;
w(find(w>100))=100;

% Put likelihoods on a log scale
w=log10(w);

% Map likelihoods to (0,1)
w=(w(:)+2)/4;

% Get indices of same and opposite polarity edge pairs
si=find(thd<pi/2|thd>=3*pi/2);
oi=find(thd>=pi/2&thd<3*pi/2);

% Get indices of edge pairs on left and right
ri=find(phi<pi/2|phi>=3*pi/2);
li=find(phi>=pi/2&phi<3*pi/2);

% Get indices of edges to plots
ind=[intersect(si,ri);intersect(oi,li)];

% Plot likelihoods
disp 'Plotting figure 1'
plot(1,d(ind),phi(ind),thd(ind),w(ind));
title('Edge pair likelihoods');

% Read histogram
fn='kodak_counts_16_8_72_72.txt';
[same,diff]=readhist(fn,16,72,72);

% Get cooccurrence probability
c=same+diff;
c=c./sum(c(:));

% Normalize each distance ring so that you can see the
% structure in the outer rings.
for ring=1:16
    c(ring,:)=c(ring,:)/max(c(ring,:));
end

% Lookup values from the cooccurrence probability table
w=lookup(d,phi,thd,c,8);

% Put cooccurrences on a log scale from 0.001 to 1.0
w=(log10(w)+3)/3;
w(find(w<0))=0;

% Plot cooccurrences
disp 'Plotting figure 2'
plot(2,d(ind),phi(ind),thd(ind),w(ind));
title('Edge pair cooccurrence probabilities, normalized by distance');

function plot(n,d,p,t,w)
% Plot the geometries
figure(n)
plotgeometry(d,p,t,w,4,true);
xlabel('x offset in pixels')
ylabel('y offset in pixels')
xlim([-128 128])
ylim([-128 128])
