%
% SparseLab Pandore toolbox
%
% GREYC IMAGE
% 6 Boulevard Marechal Juin
% F-14050 Caen Cedex
%
% Please to email any bugs, comments, and/or additions to this file see:
% http://www.greyc.ensicaen.fr/EquipeImage/Pandore
%
%(C) Jalal Fadili - 2007-12-3
%
% Forward and inverse wave atom transform examples.
% Display numerical reconstruction error.

%img = ReadImage('Lenna');
img = double(imread('data_fingerprint.jpg'));
%img = randn(1024,1024);

cwd=pwd;

cd ~/Matlab/WaveLab802/WaveAtom/codeC/SparseLab1.1/matlab

disp('------------------------------------')
disp('Fast orthogonal wave atom transform')
disp('------------------------------------')

for tp1=[-1,1]
for tp2=[-1,1]
 disp('------------------------------------')
 fprintf('Forward transform tp = [%d %d]\n',tp1,tp2)
 disp('------------------------------------')
 tic;c = fatom2sym(img, 'p', [tp1 tp2]);ts=toc;
 fprintf('Mex code %f seconds.\n',ts);
 cd ..;tic;c2 = fatom2sym(img, 'p', [tp1 tp2]);ts=toc;cd matlab
 fprintf('Matlab code %f seconds.\n',ts);
 disp('------------------------------------')
 fprintf('Inverse transform tp = [%d %d]\n',tp1,tp2)
 disp('------------------------------------')
 tic;xr = iatom2sym(c, 'p', [tp1 tp2]);ts=toc;
 fprintf('Mex code %f seconds.\n',ts);
 cd ..;tic;xr2 = iatom2sym(c2, 'p', [tp1 tp2]);ts=toc;cd matlab
 fprintf('Mex code %f seconds.\n',ts);
 % Display numerical reconstruction error.
 fprintf('Mex code: RMSE of reconstruction is %e\n',norm(xr(:)-img(:))/sqrt(prod(size(img))));
 fprintf('Matlab code: RMSE of reconstruction is %e\n',norm(xr2(:)-img(:))/sqrt(prod(size(img))));
end
end


disp('------------------------------------------------------')
disp('Fast wave atom tight frame transform with redundancy 2')
disp('------------------------------------------------------')

disp('------------------------------------')
fprintf('Forward transform \n')
disp('------------------------------------')
tic;c = fatomfm2sym(img, 'p');ts=toc;
fprintf('Mex code %f seconds.\n',ts);
cd ..;tic;c2 = fatfm2sym(img, 'p');ts=toc;cd matlab
fprintf('Matlab code %f seconds.\n',ts);
disp('------------------------------------')
fprintf('Inverse transform \n')
disp('------------------------------------')
tic;xr = iatomfm2sym(c, 'p');ts=toc;
fprintf('Mex code %f seconds.\n',ts);
cd ..;tic;xr2 = iatfm2sym(c2, 'p');ts=toc;cd matlab
fprintf('Matlab code %f seconds.\n',ts);
% Display numerical reconstruction error.
fprintf('Mex code: RMSE of reconstruction is %e\n',norm(xr(:)-img(:))/sqrt(prod(size(img))));
fprintf('Matlab code: RMSE of reconstruction is %e\n',norm(xr2(:)-img(:))/sqrt(prod(size(img))));

cd(cwd)
