 wname = 'db10'
% load image
load wbarb

% compute DWT
mode = 'sym'
[CA,CH,CV,CD] = dwt2(X,wname,'mode',mode);

% compute energies

figure(1) 
subplot(1,2,1)
imshow(X,[]);
title('original');
subplot(1,2,2)
imshow([CA,CV; CH,CD],[]);

title('DWT transform');

Z = zeros(size(CA));
XA = idwt2(CA,Z,Z,Z,wname,'mode',mode);
XH = idwt2(Z,CH,Z,Z,wname,'mode',mode);
XV = idwt2(Z,Z,CV,Z,wname,'mode',mode);
XD = idwt2(Z,Z,Z,CD,wname,'mode',mode);

figure(2)
subplot(1,2,1)
imshow(CA,[]);
title('Aproximation coefficients');
subplot(1,2,2)
imshow(XA,[]);
title('Reconstructed aproximation');



figure(3)
subplot(1,2,1)
imshow(CH,[])
title('Horizontal coefficients');
subplot(1,2,2)
imshow(XH,[]);
title('Reconstructed horizontal detail');


figure(4)
subplot(1,2,1)
imshow(CV,[])
title('Vertical coefficients');
subplot(1,2,2)
imshow(XV,[]);
title('Reconstructed vertical detail');


figure(5)
subplot(1,2,1)
imshow(CD,[])
title('Diagonal coefficients');
subplot(1,2,2)
imshow(XD,[]);
title('Reconstructed diagonal detail');

figure(6)
subplot(1,2,1)
imshow(XA,[])
title('Reconstructed aproximation');
subplot(1,2,2)
imshow(XH+XV+XD,[]);
title('Reconstructed detail');

total_energy = energy(X) 
approximation_energy_percent = 100*energy(XA)/total_energy 
detail_energy_percent = 100*energy(XH+XV+XD)/total_energy 
