clc
clear
x1= imread('lena.bmp');
im=double(x1);
En1 = entropy(x1)
% Start from the Haar wavelet and get the
% corresponding lifting scheme.
lshaar = liftwave('haar');
% Add a primal ELS to the lifting scheme.
els = {'p',[-0.125 0.125],0};
lshaarInt = liftwave('haar','int2int');
lsnewInt = addlift(lshaarInt,els);
%%%%%%%%%%%%%%%%%%%%%%%%Perform LWT for 9 level%%%%%%%%%%%%%%%%%%%%%%%%%%%%
[cAint,cHint,cVint,cDint] = lwt2(im,lsnewInt);
test=[cAint,cHint;cVint,cDint];
%%%%%%%%%%%%%%%%%%%%%%%%Perform invert LWT until 9 level%%%%%%%%%%%%%%%%%%%%%%%%%%%%
xRecInt = ilwt2(cAint,cHint,cVint,cDint,lsnewInt);
errInt = max(max(abs(im-xRecInt)))
level1=[cAint,cHint;cVint,cDint];
cAintk=int8(cAint);
one=[cAintk,cHint;cVint,cDint]; %int8
test1=[cAintk,cHint;cVint,cDint];
figure(2);
imshow(one);
title('leve1 1 suband');
%calculate entropy
%convert to positive integer
for y=1:512;
for x=1:512;
if test1(x,y)==0;
PixPos(x,y)=1;
else if test1(x,y)>0;
PixPos(x,y)=(test1(x,y)*2)+1;
else
PixPos(x,y)=abs(test1(x,y))*2;
end
end
end
end
%calculate frequency occurence of symbols
FreqPixInt(1:512)=0;
for y=1:512 %all pixel values in rows
for x=1:512 %all pixel values in columns
FreqPixInt(PixPos(x,y)+1)=FreqPixInt(PixPos(x,y)+1)+1;
end
end
FreqPixInt;
%calculate entropy of symbols(positive integer)
En2=0;% initialize value entropy to 0
for i=1:512 % all pixels value in first rows
if FreqPixInt(i)==0
En2=En2; %dummy
else
En2=En2+(FreqPixInt(i)/262144)*log2(FreqPixInt(i)/262144); %512x512=262144 total pixels
end
end
En2=En2*(-1)