clc;clear; close all;

im = double(imread('pics/MRI_Coronal_Brain.jpg'));

im=imresize(im,[256 256]); [n1,n2]=size(im);
wav = daubcqf(2);
imwt0=mdwt(im, wav, 3);
[ca,ch,cv,cd] = dwt2(im,'db1','mode','sym');

imwt(1:n1/2,1:n2/2)=ca; imwt(1:n1/2,1+n2/2:n2)=ca;
imwt(1+n1/2:n1,1:n2/2)=ca; imwt(1+n1/2:n1,1+n2/2:n2)=ca;

im2=idwt2(ca,ch,cv,cd,'db1');

figure; subplot(2,2,1); imshow(im,[]);
subplot(2,2,2); imshow(im2,[]);
subplot(2,2,3); imshow(imwt,[]);
subplot(2,2,4); imshow(imwt0,[]);

diff=norm(im2(:)-im(:),2)/norm(im(:),2)