clear all
close all
%  [aaf, ssf] = Lift53;
% af = aaf{1};
% sf = ssf{1};
% %   [af, sf] = bior22filter;
% imagedata = zeros(32,32);
% %  imagedata(13,13) = 100;
% w = dwt2D(imagedata, 1, af);
%  w{1}{1}(6,6) = 100;
% rec = idwt2D(w, 1, sf);
% c = dwtcell2arr(w, 1);
% imshow([c, rec], [])
% calcpsnr(rec, imagedata)
% lsi53 = {'p', [-0.5 -0.5], [1], [0];'u', [0.25 0.25], [0], [0]; [1], [1/2], [], []};
lsia = {'p', [-0.75 -0.25], [0], [0];'u', [0.125 0.375], [0], [1]; [1], [1], [], []};
% imagedata  = rotplane(64,64, 135);
% imagedata = double(imread('barbara.pgm'));
imagedata = zeros(256,256);
J = 3;
[y, dinfo, pinfo] = DLifting2D(imagedata, J, lsia);
% coeff = dwtcell2arr(y, J);
% M = max(max(abs(coeff)))
% 
% fid = fopen('e:\\coeff','w');
% fwrite(fid, coeff', 'int32');
% fclose(fid);


% fid = fopen('coeff_matlab');
% coeff = fread(fid, [512,512], 'int32');
% fclose(fid);
% figure;imshow(double(coeff'), [])

% fid = fopen('e:\\coeff_r','r');
% coeff_r = fread(fid,[512,512],'int32');
% coeff_r=coeff_r';
% fclose(fid);
% % figure;imshow(coeff_r, [])
% 

drec = 7;
dinfo{J}{1}=drec*ones(size(dinfo{1}{1}));
dinfo{J}{2}=drec*ones(size(dinfo{1}{2}));
dinfo{J}{3}=drec*ones(size(dinfo{1}{3}));
y{J}{1}(15,5)=100;
y{J}{2}(15,15)=100;
y{J}{3}(15,25)=100;
 y_r = y;

% y_r = dwtarr2cell(coeff_r, J);
recimage = iDLifting2D(y_r, J, dinfo, pinfo, lsia);
% 
figure; imshow(recimage, [])
calcpsnr(imagedata, recimage)