how to calculate entropy in matlab for lossless image compression ?

6 次查看(过去 30 天)
hi, I already perform iwt coding for the lossless image compression with image size 512x512 but I don't know how to calculate the entropy in Matlab coding. can anybody help me? below is my iwt coding;
  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%%%%%%%%%%%%%%%%%%%%%%%%%%%%
[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)

请先登录,再进行评论。

采纳的回答

Abhishek Ballaney
Abhishek Ballaney 2018-2-22
https://in.mathworks.com/help/images/ref/entropy.html

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Discrete Multiresolution Analysis 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by