close all;
clear all;
imagedata = double(imread('lena512.bmp'));
% imagedata = rotplane(32,32, 45);
[Faf, Fsf] = Lift53;
[af, sf] = Lift53;
J = 1;
T1 = 128;
T2 = 1;
Step = -1;
T = T1:Step:T2;
k=1.6;
wdt = dualtree2D(imagedata, J, Faf, af);
% wdtns = dtns2D(imagedata, wdt, J, Faf, af, Fsf, sf, T, k);

% Configuration 1
% [coeff, realpart, imagepart] = dtcell2arr(wdtns, J)
% Configuration 2
% step1: my = dtmerge(wdtns, J);
% step2: allceoff = dwtcell2arr(my, J);
 my = dtmerge(wdt, J);
allceoff = dwtcell2arr(my, J);

fid = fopen('e:\\coeff_','w');
fwrite(fid, coeff', 'int32');
fclose(fid);

%my_r = dwtarr2cell(allceoff,J);
wdt_r = idtmerge(allceoff,J);
% [coeff_r, realpart, imagpart] = dtcell2arr(wdt_r, J)
% coeff = [realpart, imagepart];
% y = dtarr2cell(coeff_r, J);
recimage = idualtree2D(wdt_r, J, Fsf, sf);
calcpsnr(recimage, imagedata)
max(max((abs(recimage-imagedata))))
min(min((abs(recimage-imagedata))))
figure;
imshow(recimage, [])