% Test my wazlet on a delta function
% CCK 2018-Mar-17

N = 128
image = zeros(N,N);
image(N/2,N/2) = 1;

figure(1)
hold off
imagesc(image)
colormap(gray)
axis equal
axis tight
title('Test image')

Naz = 8;
[Waz, W, theta0] = wazlet(image, 8, Naz);

%%%%%%%%% A TROUS PART %%%%%%%%%
% Plot a cut through the response to the delta function
figure(2)
hold off
for j=1:9
   plot(W(:,N/2,j))
   hold on
end
title('Cut through W for a delta function')


% Look at each layer, renormalized to unit peak intensity
B = W;
for j=1:9
   B(:,:,j) = W(:,:,j)/max(max(W(:,:,j)));
end

% Plot a cut through the response to the delta function
figure(3)
hold off
for j=1:9
   plot(B(:,N/2,j))
   hold on
end
title('A trous elements renormalized to unit maximum')

figure(4)
hold off
imagesc( [B(:,:,1), B(:,:,2), B(:,:,3); B(:,:,4), B(:,:,5), B(:,:,6); B(:,:,7), B(:,:,8), B(:,:,9) ] )
colormap(gray)
axis equal
axis tight
title('Layers of the A Trous Transform')

% Lookat each wazlet, renormalized to unit peak intensity
C = Waz;
for j=1:9
   for k=1:Naz
      C(:,:,j,k) = C(:,:,j,k)/max(max(C(:,:,j,k)));
   end
end
figure(5)
hold off
imagesc( [ C(:,:,1,1), C(:,:,2,1), C(:,:,3,1), C(:,:,4,1);...
           C(:,:,1,2), C(:,:,2,2), C(:,:,3,2), C(:,:,4,2);...
           C(:,:,1,3), C(:,:,2,3), C(:,:,3,3), C(:,:,4,3) ] );
colormap(gray)
axis equal
axis tight
title('Example Wazlets')

% reconstruction
recon = sum(sum(Waz, 4), 3);
residuals = image - recon;
absolute_max_residual = max(max(abs(residuals)))
total_abs_residual = sum(sum(abs(residuals)))
%{
figure(6)
hold off
imagesc(residuals)
colormap(gray)
axis equal
axis tight
title('Residuals')
%}



