 wname = 'db2'
% load image
load wbarb

% compute DWT
[CA,CH,CV,CD] =dwtper2(X,wname);

% compute energies
ae = mu(CA,CA) 
he = mu(CH,CH) 
ve = mu(CV,CV) 
de = mu(CD,CD) 

ma = max(abs(CA(:))) 
mh = max(abs(CH(:)))
mv = max(abs(CV(:)))
md = max(abs(CD(:))) 

figure(1)
imshow(X,[]);
title('original')
figure(2) 
imshow([CA,CV; CH,CD],[]);
title('level 1 transform')
figure(3)
imshow([CA/ma,CV/mv;CH/mh,CD/md],[]);
title('normalized level 1 transform')

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


figure(5)
subplot(2,2,1)
imshow(XA,[]);
title('approximation')
subplot(2,2,2);
imshow(XH,[]);
title('horizontal details')
subplot(2,2,3);
imshow(XV,[]);
title('vertical details')
subplot(2,2,4);
imshow(XD,[]);
title('diagonal details')
figure(6)
imshow([XA,XH+XV+XD],[]);
title('approximation and details')

%Energy calculation

wae = mu(CA,CA) 
whe = mu(CH,CH) 
wve = mu(CV,CV) 
wde = mu(CD,CD) 
xae = mu(XA,XA) 
xhe = mu(XH,XH) 
xve = mu(XV,XV) 
xde = mu(XD,XD) 

[wae,whe,wve,wde]
[xae,xhe,xve,xde]

