HOW TO CALCULATE ENTROPY FOR IWT ?

조회 수: 1 (최근 30일)
nur aqila
nur aqila 2018년 2월 20일
댓글: nur aqila 2018년 2월 21일
hi, I already perform iwt coding. I have "case" command which allows me to choose at which level I want to perform image decomposition for iwt coding. I already calculate the entropy but the resulted value seems wrong. can you check my coding and let me know which part that I'm wrong. The entropy value is decreasing at each level. these are my codings;
  댓글 수: 1
nur aqila
nur aqila 2018년 2월 21일
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%%%%%%%%%%%%%%%%%%%%%%%%%%%% n=9;
switch n case 1 [cAint,cHint,cVint,cDint] = lwt2(im,lsnewInt); test=[cAint,cHint;cVint,cDint];
case 2
[cAint,cHint,cVint,cDint] = lwt2(im,lsnewInt);
x2=double(cAint);
[cAint2,cHint2,cVint2,cDint2] = lwt2(x2,lsnewInt);
test=[cAint2,cHint2;cVint2,cDint2];
case 3
[cAint,cHint,cVint,cDint] = lwt2(im,lsnewInt);
x2=double(cAint);
[cAint2,cHint2,cVint2,cDint2] = lwt2(x2,lsnewInt);
x3=double(cAint2);
[cAint3,cHint3,cVint3,cDint3] = lwt2(x3,lsnewInt);
test=[cAint3,cHint3;cVint3,cDint3];
case 4
[cAint,cHint,cVint,cDint] = lwt2(im,lsnewInt);
x2=double(cAint);
[cAint2,cHint2,cVint2,cDint2] = lwt2(x2,lsnewInt);
x3=double(cAint2);
[cAint3,cHint3,cVint3,cDint3] = lwt2(x3,lsnewInt);
x4=double(cAint3);
[cAint4,cHint4,cVint4,cDint4] = lwt2(x4,lsnewInt);
test=[cAint4,cHint4;cVint4,cDint4];
case 5
[cAint,cHint,cVint,cDint] = lwt2(im,lsnewInt);
x2=double(cAint);
[cAint2,cHint2,cVint2,cDint2] = lwt2(x2,lsnewInt);
x3=double(cAint2);
[cAint3,cHint3,cVint3,cDint3] = lwt2(x3,lsnewInt);
x4=double(cAint3);
[cAint4,cHint4,cVint4,cDint4] = lwt2(x4,lsnewInt);
x5=double(cAint4);
[cAint5,cHint5,cVint5,cDint5] = lwt2(x5,lsnewInt);
test=[cAint5,cHint5;cVint5,cDint5];
case 6
[cAint,cHint,cVint,cDint] = lwt2(im,lsnewInt);
x2=double(cAint);
[cAint2,cHint2,cVint2,cDint2] = lwt2(x2,lsnewInt);
x3=double(cAint2);
[cAint3,cHint3,cVint3,cDint3] = lwt2(x3,lsnewInt);
x4=double(cAint3);
[cAint4,cHint4,cVint4,cDint4] = lwt2(x4,lsnewInt);
x5=double(cAint4);
[cAint5,cHint5,cVint5,cDint5] = lwt2(x5,lsnewInt);
x6=double(cAint5);
[cAint6,cHint6,cVint6,cDint6] = lwt2(x6,lsnewInt);
test=[cAint6,cHint6;cVint6,cDint6];
case 7
[cAint,cHint,cVint,cDint] = lwt2(im,lsnewInt);
x2=double(cAint);
[cAint2,cHint2,cVint2,cDint2] = lwt2(x2,lsnewInt);
x3=double(cAint2);
[cAint3,cHint3,cVint3,cDint3] = lwt2(x3,lsnewInt);
x4=double(cAint3);
[cAint4,cHint4,cVint4,cDint4] = lwt2(x4,lsnewInt);
x5=double(cAint4);
[cAint5,cHint5,cVint5,cDint5] = lwt2(x5,lsnewInt);
x6=double(cAint5);
[cAint6,cHint6,cVint6,cDint6] = lwt2(x6,lsnewInt);
x7=double(cAint6);
[cAint7,cHint7,cVint7,cDint7] = lwt2(x7,lsnewInt);
test=[cAint7,cHint7;cVint7,cDint7];
case 8
[cAint,cHint,cVint,cDint] = lwt2(im,lsnewInt);
x2=double(cAint);
[cAint2,cHint2,cVint2,cDint2] = lwt2(x2,lsnewInt);
x3=double(cAint2);
[cAint3,cHint3,cVint3,cDint3] = lwt2(x3,lsnewInt);
x4=double(cAint3);
[cAint4,cHint4,cVint4,cDint4] = lwt2(x4,lsnewInt);
x5=double(cAint4);
[cAint5,cHint5,cVint5,cDint5] = lwt2(x5,lsnewInt);
x6=double(cAint5);
[cAint6,cHint6,cVint6,cDint6] = lwt2(x6,lsnewInt);
x7=double(cAint6);
[cAint7,cHint7,cVint7,cDint7] = lwt2(x7,lsnewInt);
x8=double(cAint7);
[cAint8,cHint8,cVint8,cDint8] = lwt2(x8,lsnewInt);
test=[cAint8,cHint8;cVint8,cDint8];
case 9
[cAint,cHint,cVint,cDint] = lwt2(im,lsnewInt);
x2=double(cAint);
[cAint2,cHint2,cVint2,cDint2] = lwt2(x2,lsnewInt);
x3=double(cAint2);
[cAint3,cHint3,cVint3,cDint3] = lwt2(x3,lsnewInt);
x4=double(cAint3);
[cAint4,cHint4,cVint4,cDint4] = lwt2(x4,lsnewInt);
x5=double(cAint4);
[cAint5,cHint5,cVint5,cDint5] = lwt2(x5,lsnewInt);
x6=double(cAint5);
[cAint6,cHint6,cVint6,cDint6] = lwt2(x6,lsnewInt);
x7=double(cAint6);
[cAint7,cHint7,cVint7,cDint7] = lwt2(x7,lsnewInt);
x8=double(cAint7);
[cAint8,cHint8,cVint8,cDint8] = lwt2(x8,lsnewInt);
x9=double(cAint8);
[cAint9,cHint9,cVint9,cDint9] = lwt2(x9,lsnewInt);
test=[cAint9,cHint9;cVint9,cDint9];
otherwise
En = entropy(x1);
end
%%%%%%%%%%%%%%%%%%%%%%%%Perform invert LWT until 9 level%%%%%%%%%%%%%%%%%%%%%%%%%%%%
if n==1; 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');
elseif n==2; xRecInt2 = ilwt2(cAint2,cHint2,cVint2,cDint2,lsnewInt); errInt2 = max(max(abs(x2-xRecInt2))) one(1:128,1:128)=int8(cAint2); one(129:256,1:128)=int8(cHint2); one(1:128,129:256)=int8(cVint2); one(129:256,129:256)=int8(cDint2); level2=[cAint2,cHint2;cVint2,cDint2]; two=[level2,cHint;cVint,cDint]; test1=[level2,cHint;cVint,cDint]; figure(3); imshow(int8(two)); title('leve1 2 suband');
elseif n==3;
xRecInt3 = ilwt2(cAint3,cHint3,cVint3,cDint3,lsnewInt);
errInt3 = max(max(abs(x3-xRecInt3)))
one(1:64,1:64)=cAint3;
one(65:128,1:64)=cHint3;
one(1:64,65:128)=cVint3;
one(65:128,65:128)=cDint3;
level3=[cAint3,cHint3;cVint3,cDint3]; %level3=128x128,cAint3,cHint3,cVint3,cDint3=64x64
tiga=[level3,cHint2;cVint2,cDint2]; %three=256x256, level3,cHint2;cVint2,cDint2=128x128
three=[tiga,cHint;cVint,cDint];%three=512x512, three,cHint;cVint,cDint=256x256
test1=[tiga,cHint;cVint,cDint];
figure(4);
imshow(uint8(three));
title('leve1 3 suband');
elseif n==4;
xRecInt4 = ilwt2(cAint4,cHint4,cVint4,cDint4,lsnewInt);
errInt4 = max(max(abs(x4-xRecInt4)))
one(1:32,1:32)=cAint4;
one(33:64,1:32)=cHint4;
one(1:32,33:64)=cVint4;
one(33:64,33:64)=cDint4;
level4=[cAint4,cHint4;cVint4,cDint4]; %level4=64x64,cAint3,cHint3,cVint3,cDint3=32x32
empat=[level4,cHint3;cVint3,cDint3]; %empat=128x128, level3,cHint2;cVint2,cDint2=64x64
four1=[empat,cHint2;cVint2,cDint2]; %three=256x256, three,cHint;cVint,cDint=128x128
four=[four1,cHint;cVint,cDint];
test1=[four1,cHint;cVint,cDint];
figure(5);
imshow(uint8(four));
title('leve1 4 suband');
elseif n==5;
xRecInt5 = ilwt2(cAint5,cHint5,cVint5,cDint5,lsnewInt);
errInt5 = max(max(abs(x5-xRecInt5)))
one(1:16,1:16)=cAint5;
one(17:32,1:16)=cHint5;
one(1:16,17:32)=cVint5;
one(17:32,17:32)=cDint5;
level5=[cAint5,cHint5;cVint5,cDint5]; %level5=32x32,cAint3,cHint3,cVint3,cDint3=16x16 5
lima=[level5,cHint4;cVint4,cDint4]; %lima=64x64, level5,cHint2,cVint2,cDint2=32x32 4
five1=[lima,cHint3;cVint3,cDint3]; %five1=128x128, lima,cHint3,cVint3,cDint3=64x64 3
five2=[five1,cHint2;cVint2,cDint2]; % five2=256x256 five1,cHint2,cVint2,cDint2=128x128 2
five=[five2,cHint;cVint,cDint]; %five=512x512 five2,cHint;cVint,cDint=256x256 1
test1=[five2,cHint;cVint,cDint];
figure(6);
imshow(uint8(five));
title('leve1 5 suband');
elseif n==6;
xRecInt6 = ilwt2(cAint6,cHint6,cVint6,cDint6,lsnewInt);
errInt6 = max(max(abs(x6-xRecInt6)))
one(1:8,1:8)=cAint6;
one(9:16,1:8)=cHint6;
one(1:8,9:16)=cVint6;
one(9:16,9:16)=cDint6;
level6=[cAint6,cHint6;cVint6,cDint6]; %level6=16x16,cAint3,cHint3,cVint3,cDint3=8x8 6
six1=[level6,cHint5;cVint5,cDint5]; %six1=32x32, level6,cHint2,cVint2,cDint2=16x16 5
six2=[six1,cHint4;cVint4,cDint4]; %six2=64x64, six1,cHint4,cVint4,cDint4=32x32, 4
six3=[six2,cHint3;cVint3,cDint3]; %six3=128x128, lima,cHint3,cVint3,cDint3=64x64 3
six4=[six3,cHint2;cVint2,cDint2]; %six4=256x256, =128x128 ,six3,cHint2;cVint2,cDint2=128x128 2
six=[six4,cHint;cVint,cDint];
test1=[six4,cHint;cVint,cDint];
figure(7);
imshow(uint8(six));
title('leve1 6 suband');
elseif n==7;
xRecInt7 = ilwt2(cAint7,cHint7,cVint7,cDint7,lsnewInt);
errInt7 = max(max(abs(x7-xRecInt7)))
one(1:4,1:4)=cAint7;
one(5:8,1:4)=cHint7;
one(1:4,5:8)=cVint7;
one(5:8,5:8)=cDint7;
level7=[cAint7,cHint7;cVint7,cDint7];
seven2=[level7,cHint6;cVint6,cDint6]; %level6=16x16,cAint3,cHint3,cVint3,cDint3=8x8
seven3=[seven2,cHint5;cVint5,cDint5]; %six1=32x32, level6,cHint2,cVint2,cDint2=16x16
seven4=[seven3,cHint4;cVint4,cDint4]; %six2=64x64, six1,cHint4,cVint4,cDint4=32x32,
seven5=[seven4,cHint3;cVint3,cDint3]; %six3=128x128, lima,cHint3,cVint3,cDint3=64x64
seven6=[seven5,cHint2;cVint2,cDint2]; %six4=256x256, =128x128 ,six3,cHint2;cVint2,cDint2=128x128
seven=[seven6,cHint;cVint,cDint];
test1=[seven6,cHint;cVint,cDint];
figure(8);
imshow(uint8(seven));
title('leve1 7 suband');
elseif n==8;
xRecInt8 = ilwt2(cAint8,cHint8,cVint8,cDint8,lsnewInt);
errInt8 = max(max(abs(x8-xRecInt8)))
one(1:2,1:2)=cAint8;
one(3:4,1:2)=cHint8;
one(1:2,3:4)=cVint8;
one(3:4,3:4)=cDint8;
level8=[cAint8,cHint8;cVint8,cDint8];
eight1=[level8,cHint7;cVint7,cDint7];
eight2=[eight1,cHint6;cVint6,cDint6]; %level6=16x16,cAint3,cHint3,cVint3,cDint3=8x8
eight3=[eight2,cHint5;cVint5,cDint5]; %six1=32x32, level6,cHint2,cVint2,cDint2=16x16
eight4=[eight3,cHint4;cVint4,cDint4]; %six2=64x64, six1,cHint4,cVint4,cDint4=32x32,
eight5=[eight4,cHint3;cVint3,cDint3]; %six3=128x128, lima,cHint3,cVint3,cDint3=64x64
eight6=[eight5,cHint2;cVint2,cDint2]; %six4=256x256, =128x128 ,six3,cHint2;cVint2,cDint2=128x128
eight=[eight6,cHint;cVint,cDint];
test1=[eight6,cHint;cVint,cDint];
figure(9);
imshow(uint8(eight));
title('leve1 8 suband');
else
xRecInt9 = ilwt2(cAint9,cHint9,cVint9,cDint9,lsnewInt);
errInt9 = max(max(abs(x9-xRecInt9)))
one(1:1.5,1:1.5)=cAint9;
one(1.6:2,1:1.5)=cHint9;
one(1:1.5,1.6:2)=cVint9;
one(1.6:2,1.6:2)=cDint9;
level9=[cAint9,cHint9;cVint9,cDint9];
nine1=[level9,cHint8;cVint8,cDint8];
nine2=[nine1,cHint7;cVint7,cDint7];
nine3=[nine2,cHint6;cVint6,cDint6]; %level6=16x16,cAint3,cHint3,cVint3,cDint3=8x8
nine4=[nine3,cHint5;cVint5,cDint5]; %six1=32x32, level6,cHint2,cVint2,cDint2=16x16
nine5=[nine4,cHint4;cVint4,cDint4]; %six2=64x64, six1,cHint4,cVint4,cDint4=32x32,
nine6=[nine5,cHint3;cVint3,cDint3]; %six3=128x128, lima,cHint3,cVint3,cDint3=64x64
nine7=[nine6,cHint2;cVint2,cDint2]; %six4=256x256, =128x128 ,six3,cHint2;cVint2,cDint2=128x128
nine=[nine7,cHint;cVint,cDint];
test1=[nine7,cHint;cVint,cDint];
figure(10);
imshow(uint8(nine));
title('leve1 9 suband');
end
%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)

댓글을 달려면 로그인하십시오.

답변 (0개)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by