How to compress an color image using Huffman compression in matlab?
Mostrar comentarios más antiguos
How to compress an color image using Huffman compression and also how to decompress it using Huffman decompression in matlab?
2 comentarios
Anushka
el 27 de Jun. de 2015
Avinash Macharla
el 23 de Sept. de 2018
Editada: Walter Roberson
el 12 de Abr. de 2019
filename = input('enter the image file name', 's');
string = imread(filename);
string = string(:); %input string
symbol=[]; %initialise variables
count=[];
j=1;
%------------------------------------------loop to separate symbols and how many times they occur for i=1:length(string)
flag=0;
flag=ismember(symbol,string(i)); %symbols
if sum(flag)==0
symbol(j) = string(i);
k=ismember(string,string(i));
c=sum(k); %no of times it occurs
count(j) = c;
j=j+1;
end
end
ent=0;
total=sum(count); %total no of symbols
prob=[];
%-----------------------------------------for loop to find probability and %entropy
for i=1:1:size((count)');
prob(i)=count(i)/total;
ent=ent-prob(i)*log2(prob(i));
end
var=0;
%-----------------------------------------function to create dictionary [dict avglen]=huffmandict(symbol,prob);
% print the dictionary.
temp = dict;
for i = 1:length(temp)
temp{i,2} = num2str(temp{i,2});
var=var+(length(dict{i,2})-avglen)^2; %variance calculation
end
temp
%-----------------------------------------encoder and decoder functions
sig_encoded=huffmanenco(string,dict)
deco=huffmandeco(sig_encoded,dict);
equal = isequal(string,deco)
%-----------------------------------------decoded string and output %variables
str ='';
for i=1:length(deco)
str= strcat(str,deco(i));
end
disp('**str**')
str
disp('**ent**')
ent
disp('**avglen**')
avglen
disp('**var**')
var
Respuestas (1)
Walter Roberson
el 27 de Jun. de 2015
0 votos
reshape() the content of the image into a vector. Then use Huffman encoding on the vector.
When decoding, decode the encoding data into a vector and reshape() the vector into a 3D array.
5 comentarios
Anushka
el 27 de Jun. de 2015
merr LAMINe
el 11 de Abr. de 2019
Where is the benefit after encoding followed by decoding Huffman !. Decoding will produce the same encoded vector .
Walter Roberson
el 12 de Abr. de 2019
Well, you certainly hope that it produces the same vector, but you might have an error in your encoding process or in your decoding process.
It is common for people not to realize that the point of huffman encoding is to be able to create bit vectors with the encoded values, one bit per element, rather than 1 double per element as is returned by the MATLAB huffman encoding routine.
Bhaumik chaudhari
el 22 de Sept. de 2020
can you send me the code my email id:bhaumikchaudhari225@gmail.com
Walter Roberson
el 22 de Sept. de 2020
The code for exactly what, Bhaumik chaudhari ? Do you need to be able to do Huffman encoding on CT reconstructions read in from DICOM files?
Categorías
Más información sobre Denoising and Compression en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!