% Chapter 12, Fig.12.6
% Eric Dubois, updated 2019-01-15
%Illustrating periodicity with various symmetries

clear all, close all
filename = '05.tif';
Afull = im2double(imread(filename));
M = 64; R = 4;
xoff = 334; yoff = 192; %for motorcycles (Kodak 05)
Ablk = Afull(yoff:yoff+M-1, xoff:xoff+M-1,:);
%no symmetry
A_nosym = repmat(Ablk,[R R 1]);
imshow(A_nosym)

%linear phase symmetry
Afund = Ablk(M/2+1:M,:,:);
for col=1:3
  Ablk1(:,:,col) = [fliplr(flipud(Afund(:,:,col))); Afund(:,:,col)];
end
A_linphase = repmat(Ablk1,[R R 1]);
figure, imshow(A_linphase)

%quadrantal symmetry
Afundq = Ablk(M/2+1:M,M/2+1:M,:);
for col=1:3
    Ablk2h(:,:,col) = [fliplr(Afundq(:,:,col)) Afundq(:,:,col)];
    Ablk2(:,:,col) = [flipud(Ablk2h(:,:,col)); Ablk2h(:,:,col)];
end
A_quadrantal = repmat(Ablk2,[R,R,1]);
figure, imshow(A_quadrantal)

%8-fold symmetry
for col=1:3
     Afund8(:,:,col) = triu(Afundq(:,:,col));
     Afund8q(:,:,col) = Afund8(:,:,col) + tril(Afund8(:,:,col)',-1);
     Afund8qh(:,:,col) = [fliplr(Afund8q(:,:,col)) Afund8q(:,:,col)];
     Ablk3(:,:,col)= [flipud(Afund8qh(:,:,col)); Afund8qh(:,:,col)];
end
A_8sym = repmat(Ablk3,[R R 1]);
figure, imshow(A_8sym)