how to calculate entropy in matlab for lossless image compression ?

조회 수: 3 (최근 30일)
nur aqila
nur aqila 2018년 2월 21일
댓글: nur aqila 2018년 2월 22일
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에서 Image Segmentation and Analysis에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by