clear;
close all;
% Computes the Two-dimensional Discrete Wavelet Transform
% of an image up to two levels using ''db2'' wavelet. The
% DWT coefficients are placed in a large array for display
% purpose. The innermost 4 quadrants correspond to
% LL,HL,LH, and HH coefficients at level 2.
% the three outer quadrants correspond to HL,LH, and HH
% coefficients at level 1.
%
inFile = 'cameraman.tif';
folder = fileparts(which(inFile));
A = imread(fullfile(folder,inFile));
[Height,Width,Depth] = size(A);
if Depth == 1
    f = double(A);
else
    f = double(rgb2gray(A));
end
% 2-level 2D DWT
[DWT,S] = wavedec2(f,2,'db2');
% Extract approximation & detail coefficients @ level 2 and
LL2 = appcoef2(DWT,S,'db2',2);
[HL2,LH2,HH2] = detcoef2('all',DWT,S,2);
figure,
subplot(2,2,1),imshow(wcodemat(LL2,32,'m',1),[]),title('LL_2');
subplot(2,2,2),imshow(wcodemat(HL2,32,'m',1),[]),title('HL_2');
subplot(2,2,3),imshow(wcodemat(LH2,32,'m',1),[]),title('LH_2');
subplot(2,2,4),imshow(wcodemat(HH2,32,'m',1),[]),title('HH_2');

% Now extract approx., and detail coefficients @ level 1 and
LL1 = appcoef2(DWT,S,'db2',1);
[HL1,LH1,HH1] = detcoef2('all',DWT,S,1);
figure,
subplot(2,2,1),imshow(wcodemat(LL1,32,'m',1),[]),title('LL_1');
subplot(2,2,2),imshow(wcodemat(HL1,32,'m',1),[]),title('HL_1');
subplot(2,2,3),imshow(wcodemat(LH1,32,'m',1),[]),title('LH_1');
subplot(2,2,4),imshow(wcodemat(HH1,32,'m',1),[]),title('HH_1');


