Sei sulla pagina 1di 10

11/9/2015

Huffmancodinganddecodingforimage(JPEG,BMP)MATLABAnswersMATLABCentral

0votes

Huffman coding and decoding for image(JPEG,


BMP)
AskedbyManishaMehraon28Feb2011
LatestactivityCommentedonbyWalterRobersonon23Jun2015
AcceptedAnswerbyPauloSilva
Ihavetoimplementhuffmanencodinganddecodingfora'.bmp'imagewithoutusingtheinbuiltmatlab
functionlikehuffmandict,huffmanencoandhuffmandeco.
Cananybodyhelpmebysendingmethesourcecode?
Moreover,IhavedonetheencodingpartbutIamnotabletodothedecoding.Ihavenoideaashowto
reconstructtheimagethroughdecoding.

2 Comments
DimpleAnandparaon23Jun2015
Link
iimplementgivencodeofhuffmanencodingfora.bmpfilebuttheencodestringsize
morethenactualsizeoffilecanuexplainwhy?

WalterRobersonon23Jun2015
Link
Thatispossible.Youneedtostorethecodedictionaryaswellastheencoding.With
256differentsymbolspossible,unlessatleasthalfofthemareneverused,youcanbe
surethatsomeoftheencodingswillbeatleast8bits,theoriginallength.Whenthe
probabilitiesareaboutequallydistributedeachofthesymbolswouldcomeoutas8bits,
sosavingnothingfortheencodedpart.Butyouneedtosavethedictionaryaswelland
thattakesroom.

http://www.mathworks.com/matlabcentral/answers/2158huffmancodinganddecodingforimagejpegbmp

1/10

11/9/2015

Huffmancodinganddecodingforimage(JPEG,BMP)MATLABAnswersMATLABCentral

Huffmanencodingisalosslessencoding,soyouneedtohaveasmuch"information"
storedintheencodedversionasintheunencodedversion.Itdoesn'tbegintosave
spaceontheencodinguntilsomeofthesymbolsareatleasttwiceasprobableassome
oftheothersoratleasthalfthepotentialsymbolsareneverunused,whichare
situationsthatwouldallowittosave1bitperoccurrence.Thosebitssavedhavetoadd
uptothesizeofthesaveddictionarybeforeyougetanynetsavingsonthestorage.
Efficientstorageofthedictionarytakessomethoughtsinceeachoftheentriesisa
variablenumberofbitsthebitpatternandthesymbolitdecodesto.Andrememberto
accountfortheendofstreammarkerorsomeothermethodofindicatingwheretheend
ofthestreamofbitsis,sinceitwillnotgenerallybeatabyteboundarysoyoucan'ttell
byendoffile.

Tags
sendit2me doit4me imageprocessing imagecompression imagereconstruction huffman

Products
Noproductsareassociatedwiththisquestion.

6 Answers

0votes
Link
AnswerbyPauloSilvaon28Feb2011
Acceptedanswer

http://www.mathworks.com/matlabcentral/answers/2158huffmancodinganddecodingforimagejpegbmp

2/10

11/9/2015

Huffmancodinganddecodingforimage(JPEG,BMP)MATLABAnswersMATLABCentral

Therearegoodexamplesonthematworksfileexchange,forexamplethispresentationwithsourcecode
andgoodexplanation

2 Comments
ManishaMehraon1Mar2011
Link
Thanks..
Itworkedawesome.

fatehon9Nov2014
Link
howcouldirunthisexample

0votes
Link
AnswerbyFalakon4May2012
Trythisone...justchangetoyourrequiredimage

http://www.mathworks.com/matlabcentral/answers/2158huffmancodinganddecodingforimagejpegbmp

3/10

11/9/2015

Huffmancodinganddecodingforimage(JPEG,BMP)MATLABAnswersMATLABCentral

%AuthorName:FalakShah
%Target:Tohuffmanencodeanddecodeuserenteredstring
%
string=input('enterthestringininvertedcommas');%inputstring
symbol=[];%initialisevariables
count=[];
j=1;
%looptoseparatesymbolsandhowmanytimestheyoc
fori=1:length(string)
flag=0;
flag=ismember(symbol,string(i));%symbols
ifsum(flag)==0
symbol(j)=string(i);
k=ismember(string,string(i));
c=sum(k);%nooftimesitoccurs
count(j)=c;
j=j+1;
end
end
ent=0;
total=sum(count);%totalnoofsymbols
prob=[];
%forlooptofindprobabilityand
%entropy
fori=1:1:size((count)');
prob(i)=count(i)/total;
ent=entprob(i)*log2(prob(i));
end
var=0;
%functiontocreatedictionary
[dictavglen]=huffmandict(symbol,prob);
%printthedictionary.
temp=dict;
fori=1:length(temp)
temp{i,2}=num2str(temp{i,2});
var=var+(length(dict{i,2})avglen)^2;%variancecalculation
end
temp
%encoderanddecoderfunctions
sig_encoded=huffmanenco(string,dict)
deco=huffmandeco(sig_encoded,dict);
equal=isequal(string,deco)
%decodedstringandoutput
%variables
str='';
fori=1:length(deco)
str=strcat(str,deco(i));
http://www.mathworks.com/matlabcentral/answers/2158huffmancodinganddecodingforimagejpegbmp

4/10

11/9/2015

Huffmancodinganddecodingforimage(JPEG,BMP)MATLABAnswersMATLABCentral

end
str
ent
avglen
var

4 Comments
Show1oldercomment
sailajaon31Jan2014
Link
howtousethiscodeforanimage

WalterRobersonon31Jan2014
Link
Changetheinput()callto,

filename=input('entertheimagefilename','s');
string=imread(filename);
string=string(:);

projecteon26Apr2014
Link
hihowcanidecodeaimagefromasecretimageinthesameformat

http://www.mathworks.com/matlabcentral/answers/2158huffmancodinganddecodingforimagejpegbmp

5/10

11/9/2015

Huffmancodinganddecodingforimage(JPEG,BMP)MATLABAnswersMATLABCentral

0votes
Link
Answerbyslamanajlaon19May2012
Hellopleaseisthatyoucanhelpme?isthatyoucansendmeyourregistrationcodefilesbeforeyouget
thepicturecompressedasIencounterthesameproblemasletgoofcompressedimageisavery
superiorpictureframerandmyoriginalremarkthatthefaultisintherecordingfiles.thankyouinadvance

1 Comment
WalterRobersonon19May2012
Link
Thedictionaryisdependentontheimagebeingencoded.Havingthedictionaryfora
differentimagewouldnothelpyou.

0votes
Link
Answerbyslamanajlaon19May2012
goodeveningisthatyoucanhelpme?Irealizemyenthusiasmformymastersresearchtopicis
"medicalimagecompression".theoutcomeofmyapplicationisasfollows:Ibreakmyimageinto4
subbandsLL,HH,HLandLH.then,IappliedonlosslessjpegLLandDPCMofHH,HLandLH.
thereafter,Iapplyreadingandzigzagacrossthehuffmanbandes.MaistheproblemthatIcannotfind
http://www.mathworks.com/matlabcentral/answers/2158huffmancodinganddecodingforimagejpegbmp

6/10

11/9/2015

Huffmancodinganddecodingforimage(JPEG,BMP)MATLABAnswersMATLABCentral

howtorecordallthisdatainordertohavethecompressedimagesize.isthatyoucanhelpmetofinda
matlabcodetorecordallthisdatainordertohavethecompressedimagesize.thankyouinadvancefor
helpingme

0 Comments

0votes
Link
Answerbyslamanajlaon20May2012
meproblemisinthispartie.Ifindthesizeofcompressedimageisverysuperiororiginalimage
%AlogMettrelecodede0101010...deDansunVecteurde8bitsparl'lementde%ErreurL2=
longueur(CODEH)
LCDH=round(L2/8)
simod(L2,8)<4

simod(L2,8)~=0
LCDH=LCDH+1;
fin
fin

LcdnH=(LCDH)*8
DIFLcdH=(LcdnH)L2
codnH=zeros(1,LcdnH)
k=1pouri=1:L2codnH(k)=CODEH(i)

http://www.mathworks.com/matlabcentral/answers/2158huffmancodinganddecodingforimagejpegbmp

7/10

11/9/2015

Huffmancodinganddecodingforimage(JPEG,BMP)MATLABAnswersMATLABCentral

k=k+1;
fin

Tcod8H=zeros(1,laLCDH)
k=1
pouri=1:laLCDH

pourj=00:07
Tcod8H(i)=(codnH(k+j))*(2^j)+Tcod8H(i);
fin;
k=k+8;
fin;

LTH=longueur(Tcod8H)
LXF=longueur(XfuH)
A=[]P=[]B=[]
k=1,ii=1jj=1
pouri=1:siLXFXfuH(i)>255

temp=abais(XfuH(i));
P(ii)=i;
pourj=1:2
A(k)=temp(j);
k=k+1;
fin;
ii=ii1;
d'autre
B(jj)=XfuH(i);
jj=jj+1;
fin;
fin;
l=longueur(A);
h01=redimensionnement(LXF);

%H03=redimensionnement(LT)
H02=redimensionnement(l)
H04=%redimensionnement(T)
http://www.mathworks.com/matlabcentral/answers/2158huffmancodinganddecodingforimagejpegbmp

8/10

11/9/2015

Huffmancodinganddecodingforimage(JPEG,BMP)MATLABAnswersMATLABCentral

%H05=redimensionnement(LXfu)
Fichier=[ABPh01H02Tcod8HDIFLcdHtailletaille1taille2taille3]

Taux_de_compression%=MX*NX/longueur(fichier);
Gain_de_compression%=100*(1Taux_de_compression)
Gain_de_compression%=100*(11/Taux_de_compression);
f=fopen('compressionnnnnirmwithprdiction.comp','w');

fwrite(f,Fichier,'ubit8')
fclose(f)

1 Comment
WalterRobersonon20May2012
Link
Pleaseputallthis(includingtheearlierone)codetogetherintoanewQuestionand
removeithere,asyourquestiondoesnothavemuchtodowiththeQuestionhere.
OrinsteadofanewQuestion,youshouldedityourQuestion
http://www.mathworks.com/matlabcentral/answers/38863compressionimagetohaveall
theinformationyouhaveprovidedhere.

0votes
Link
Answerbyslamanajlaon20May2012

http://www.mathworks.com/matlabcentral/answers/2158huffmancodinganddecodingforimagejpegbmp

9/10

11/9/2015

Huffmancodinganddecodingforimage(JPEG,BMP)MATLABAnswersMATLABCentral

thankyoutoyouranswer.myquestionistobeappliedaftertheDWToftheimageandlosslessjpegon
myLLandDPCMcodeisthe3subbandsLH,HLandHH.andthereafterthehuffmanencoderonfour
subbandes.enfinwhenIsavetheimagewiththiscodeIgetacompressedimageismuchhigherthan
originalimage.pleazeisthatitispossibletosendmearegistrationcode?thankyoutohelpyour

0 Comments

Discover what MATLAB can do for your career.


Opportunitiesforrecentengineeringgrads.
Applytoday

http://www.mathworks.com/matlabcentral/answers/2158huffmancodinganddecodingforimagejpegbmp

10/10

Potrebbero piacerti anche