clear;
%
% This program is to compare the ensemble and deterministic third-order statistics
% of odd and even texture images
%
M=10;
N=10;
iter=100;
%
% Average over 100 pairs to simulate the ensemble statistics
%
sumTodd=zeros(M,N,M,N);
sumTeven=zeros(M,N,M,N);
sumTcoin=zeros(M,N,M,N);
for i=1:iter
   Iodd=generateTexture(M,N,'odd');
   Todd=TriCorr2(Iodd);
   sumTodd=sumTodd+Todd;
   Ieven=generateTexture(M,N,'even');
   Teven=TriCorr2(Ieven);
   sumTeven=sumTeven+Teven;
   Icoin=generateTexture(M,N,'coin');
   Tcoin=TriCorr2(Icoin);
   sumTcoin=sumTcoin+Tcoin;
end;
 
avgTodd=sumTodd/iter;
avgTeven=sumTeven/iter;
avgTcoin=sumTcoin/iter;

%
% Generate 1 pairs of 10x10 odd, even pairs for compaison
%
iodd=generateTexture(10,10,'odd');
ieven=generateTexture(10,10,'even');
icoin=generateTexture(10,10,'coin');

Todd10=TriCorr2(iodd);
Teven10=TriCorr2(ieven);
Tcoin10=TriCorr2(icoin);

figure(1);
plot(Todd10(:),Teven10(:),'*',0:0.1:0.7,0:0.1:0.7,'-');
title('Triple correlation odd vs even 10x10');grid;
figure(2);
plot(avgTodd(:),avgTeven(:),'*',0:0.1:0.7,0:0.1:0.7,'-');
title('Average triple correlation odd vs even 10x10');grid;
figure(3);
plot(Teven10(:),Tcoin10(:),'*',0:0.1:0.7,0:0.1:0.7,'-');
title('Triple correlation even vs coin 10x10');grid;
figure(4);
plot(avgTeven(:),avgTcoin(:),'*',0:0.1:0.7,0:0.1:0.7,'-');
title('Average triple correlation even vs coin 10x10');grid;
figure(5);
plot(Tcoin10(:),Todd10(:),'*',0:0.1:0.7,0:0.1:0.7,'-');
title('Triple correlation coin vs odd 10x10');grid;
figure(6);
plot(avgTcoin(:),avgTodd(:),'*',0:0.1:0.7,0:0.1:0.7,'-');
title('Average triple correlation coin vs odd 10x10');grid;
diffToddTeven=Todd10-Teven10;
diffToddTcoin=Todd10-Tcoin10;
diffTevenTcoin=Teven10-Tcoin10;
avgDiffToddTeven=avgTodd-avgTeven;
avgDiffToddTcoin=avgTodd-avgTcoin;
avgDiffTevenTcoin=avgTeven-avgTcoin;
figure(7);
hist(diffToddTeven(:),-0.5:0.1:0.5);
title('Odd and even triple correlation difference Histogram');axis([-0.5 0.5 0 8000]);grid;
figure(8);
hist(diffToddTcoin(:),-0.5:0.1:0.5);
title('Odd and coin triple correlation difference Histogram');axis([-0.5 0.5 0 8000]);grid;
figure(9);
hist(diffTevenTcoin(:),-0.5:0.1:0.5);
title('Even and coin triple correlation difference Histogram');axis([-0.5 0.5 0 8000]);grid;
figure(10);
hist(avgDiffToddTeven(:),-0.5:0.1:0.5);
title('Odd and even average triple correlation difference Histogram');axis([-0.5 0.5 0 20000]);grid;
figure(11);
hist(avgDiffToddTcoin(:),-0.5:0.1:0.5);
title('Odd and coin average triple correlation difference Histogram');axis([-0.5 0.5 0 20000]);grid;
figure(12);
hist(avgDiffTevenTcoin(:),-0.5:0.1:0.5);
title('Even and coin average triple correlation difference Histogram');axis([-0.5 0.5 0 20000]);grid;

