% Wavelets 2001 --- Practica 2

echo on

load lena;

colormap(gray)
imagesc(lena), axis square, axis off, title('lena 256x256')

pause

% filtres de haar

h = [1/sqrt(2) 1/sqrt(2)]
g = [-1/sqrt(2) 1/sqrt(2)]

pause

% filtres bidimensionals

hh = h'*h;
hg = h'*g;
gh = g'*h;
gg = g'*g;

pause

% accio dels filtres

lenahh = conv2(hh,lena);
lenahg = conv2(hg,lena);
lenagh = conv2(gh,lena);
lenagg = conv2(gg,lena);

pause

% grafiques

colormap(gray)
imagesc(lenahh), axis square, axis off, title('lena filtrada hxh')
pause

imagesc(lenahg), axis square, axis off, title('lena filtrada hxg')
pause

imagesc(lenagh), axis square, axis off, title('lena filtrada gxh')
pause

imagesc(lenagg), axis square, axis off, title('lena filtrada gxg')
pause



% downsampling

parells = 2:2:length(lena);

lenahhd = lenahh(parells, parells);
lenahgd = lenahg(parells, parells);
lenaghd = lenagh(parells, parells);
lenaggd = lenagg(parells, parells);

pause

% normes

nl = norm(lena, 'fro')
nhh = norm(lenahhd, 'fro')
nhg = norm(lenahgd, 'fro')
ngh = norm(lenaghd, 'fro')
ngg = norm(lenaggd, 'fro')

pause

% conservacio de l'energia

sqrt(nhh^2+nhg^2+ngh^2+ngg^2)

pause

% grafiques de l'analisi

colormap(gray)
subplot(1,2,1), imagesc(lena), axis square, axis off, title('lena original')
subplot(1,2,2), imagesc([lenahhd,lenahgd;lenaghd,lenaggd])
axis square, axis off, title('lena analitzada')


