% Chapter 12, Fig.12.4
% Eric Dubois, updated 2019-01-15
% Sinusoidal signal with 8-fold symmetry on a square lattice
% Required functions:  sRGB_gamma_correction
clear all, close all;
u = .01; v = .025;
L1 = -449;
L2 = 450;
m = L1:L2; n = m;
[M, N] = meshgrid(m,n);
%sinusoid with only inversion symmetry
C_lin = .5 + .5*cos(2*pi*(u*M + v*N));
%apply sRGB gamma correction
C = sRGB_gamma_correction(C_lin);
figure
image([L1,L2],[L1,L2],C,'CDataMapping','scaled');
colormap(gray)
set(gca,'dataaspectratio',[1 1 1]);  %make the plot square
axis off
hold on
line([L1,L2],[0,0],'Color','b')
line([0,0],[L1,L2],'Color','b')
line([L1,L2],[L1,L2],'Color','r') 
line([L1,L2],[L2,L1],'Color','r')
set(gcf,'Color',[1 1 1]);
hold off
CE_lin = .5 + .125*(cos(2*pi*(u*M+v*N)) + cos(2*pi*(u*N-v*M)) ...
    +cos(2*pi*(u*M-v*N)) + cos(2*pi*(u*N+v*M)));
CE = sRGB_gamma_correction(CE_lin);
figure
image([L1,L2],[L1,L2],CE,'CDataMapping','scaled');
colormap(gray)
set(gca,'dataaspectratio',[1 1 1]);  %make the plot square
axis off
hold on
line([L1,L2],[0,0],'Color','b')
line([0,0],[L1,L2],'Color','b')
line([L1,L2],[L1,L2],'Color','r') 
line([L1,L2],[L2,L1],'Color','r')