% test
s = 30;

psnr_temp=[];
psnr_temp2 = [];
image = 'nahodny';
ridkost = 256;
rozmer = 16;
original_picture = 'lena.jpg';
baze='DWT';
wavelet='haar';
hloubka_decom =3;
pocet_hladin = 5;

tic
for i=1:s
    
   [signal_in, signal_kvant, signal_out, signal_kvant_out,  psnr, psnr_ok, psnr_kvant] = signal_dequanting2D_impl(image, ridkost, rozmer, original_picture, baze, wavelet, hloubka_decom, pocet_hladin);
    psnr_temp= [psnr_temp; psnr];
    psnr_temp2= [psnr_temp2; psnr_kvant];

    
global M;
global N;
global delta;
global rozdeleni;

P = unique(signal_out(:)); 
E = unique(signal_in);

figure
imagesc(reshape(signal_in,M,N));
colormap(gray)
axis image
title('Originalni obraz');

figure
imagesc(reshape(signal_kvant,N,N));
colormap(gray)
axis image
title('Kvantovany obraz');
 
figure
imagesc(reshape(signal_out,N,N));
colormap(gray)
axis image
title('Rekonstrukce');
 figure
 imagesc(E');
 colormap(gray)
 title('puvodni - skala hodnot');
 
  
 figure
imagesc(rozdeleni);
 colormap(gray)
 title('kvantovany - skala hodnot');
 
  
 figure
 imagesc(P');
  colormap(gray)
  title('R');
  title(' rekonstrukce - skala hodnot');
 
 
  figure
  imagesc((reshape(signal_in - signal_kvant,N,N)));
  colormap(gray)
  colorbar
  title('Rezidua: puvodni obraz vs. rekonstrukce');
  
figure
  imagesc(reshape(signal_kvant-signal_kvant_out,N,N));
  colormap(gray)
  colorbar
  title('Rezidua: kvant.original vs. kvant.rekonstrukce');

  figure
imagesc(reshape(signal_kvant_out,N,N));
  colormap(gray)
  colorbar
  title('Kvantovana rekonstrukce');

end

toc;
disp('PSNR=');
disp(mean(psnr_temp));
disp('PSNR_kvant=');
disp(mean(psnr_temp2));