Arithmetic coding explanation?
3 views (last 30 days)
Show older comments
Can any one help me in text compression by arithmetic coding
I try using the built_in function "arithenco" but i can not understand this example in description :
%The example below performs arithmetic encoding and decoding, using a source whose alphabet has three symbols.
seq = repmat([3 3 1 3 3 3 3 3 2 3],1,50);
counts = [10 10 80];
code = arithenco(seq,counts);
dseq = arithdeco(code,counts,length(seq));
I need compress text file
0 Comments
Answers (8)
Walter Roberson
on 19 May 2012
unique() your input; the result is your "alphabet". histc() your input against the alphabet. The result is the "counts". Now, arithenco the input against the counts to get the "codes".
4 Comments
Yusuf lamah
on 17 Mar 2020
ext ='yusuf lamah'
input=double(text);
[alphabet,~,seq]=unique(input)
counts = histc(input,alphabet);
code = arithenco(seq,counts);
dseq = arithdeco(code,counts,length(input));
'how i can return the original text using arithdeco function '
slama najla
on 20 May 2012
Edited: Walter Roberson
on 14 Mar 2020
moi problème est dans ce party. Je trouve la taille de l'image compressée est très supérieure image originale
Mettre le code
% Alog le 0101010 de ... de de Dans un Vecteur de 8 bits par l'élement de L2 = Erreur% length (CODEH);
LCDH = round (L2 / 8);
Si mod (L2, 8) <4
Si mod (L2, 8) ~ = 0
LCDH = LCDH +1;
nageoire
nageoire
LcdnH = (LCDH) * 8;
DIFLcdH = (LcdnH)-L2;
codnH = zeros (1, LcdnH);
k = 1; versez i = 1: L2; codnH (k) = CODEH (i);
k = k +1;
nageoire
Tcod8H = zeros (1, la LCDH);
k = 1;
versez i = 1: la LCDH
versez j = 00:07
Tcod8H (i) = (codnH (k + j)) * (2 ^ j) + Tcod8H (i);
nageoire;
k = k +8;
nageoire;
LTH = length (Tcod8H);
LXF = length (XfuH);
A = []; P = []; B = [];
k = 1, ii = 1; jj = 1;
versez i = 1: si LXF XfuH (i)> 255
temp = abais (XfuH (i));
P (ii) = i;
versez j = 1:2
A (k) = temp (j);
k = k +1;
nageoire;
ii = ii 1;
D'AUTRE
B (jj) = XfuH (i);
jj = jj +1;
nageoire;
nageoire;
l = longueur (A);
h01 = redimensionnement (LXF);
H03 =% redimensionnement (LT);
H02 = redimensionnement (l);
H04 redimensionnement% = (T);
% H05 = redimensionnement (LXfu);
Fichier = [ABP h01 H02 Tcod8H DIFLcdH taille taille1 taille2 taille3];
% Taux_de_compression = MX * NX / length (fichier);
Gain_de_compression% = 100 * (1-Taux_de_compression)
% Gain_de_compression = 100 * (1-1/Taux_de_compression);
f = fopen ('compressionnnnn irm avec prédiction.comp', 'w');
fwrite (f, Fichier, 'ubit8');
fclose (f);
0 Comments
Yusuf lamah
on 14 Mar 2020
how to use counts in the following function ARITHENCO(SEQ, COUNTS)?
16 Comments
Yusuf lamah
on 26 Mar 2020
how i can use xlawrite funtion to save the results in specific sheet and specific table in the Excel
Yusuf lamah
on 22 Mar 2020
Hello,i get warning:This is an obsolete function and may be removed in the future in randint line,please use RANDI instead "z1=randint(1,1,z); how i can use RANDI in this line instead of randint
1 Comment
Walter Roberson
on 22 Mar 2020
https://www.mathworks.com/matlabcentral/answers/375213-how-can-replace-randi-instead-randint
Yusuf lamah
on 22 Mar 2020
i get output of RSA encryption was " 9 9 9 9 9 .... " i need to use huffman to compress the encrypted data out = 9 9 9 9 The value for n_ary must be less than or equal to the number of distinct symbol. error in
symbol_probs=symbol_counts./nume1(text); H4=num2cell(unique_symbols); dict=huffmandict =accumarray(bin_number,1); the error in last line dict line
1 Comment
Walter Roberson
on 22 Mar 2020
Please post your actual code for that section . Please make sure it is formatted. Click the > Code button to get a code region and paste the code there
Yusuf lamah
on 23 Mar 2020
input=double(text);
counts=max(1,accumarray(input(:),1));
Acomp = arithenco(input,counts);
%%%%%%%%%%%%%
[unique_symbols, ~, bin_number] = unique(text(:));
symbol_counts = accumarray(bin_number, 1);
symbol_probs = symbol_counts ./ numel(text);
H4=num2cell(unique_symbols);
dict= huffmandict(H4,symbol_probs);
comp = huffmanenco(text,dict);
%%%%%%%%%%%%%
Both codes are working arithmetic and huffman but the big problem is the compression ratio in the huffman better than Arithmetic ,theoretical and practical the Arithmetic better than huffman
3 Comments
Yusuf lamah
on 23 Mar 2020
in the decode they were ok both of them return the original message but my quation why the ratio in huffman better than arithmetic sure there is something not correct on the code
Walter Roberson
on 23 Mar 2020
You are permitting Huffman to encode from a set of symbols that includes only the characters used in the message. That set of characters is stored inside the Huffman dictionary and you are permitting the Huffman decoding to access that dictionary to do the decoding, so it can return the original characters.
Arithmetic encoding does not build a dictionary. It expects symbol numbers (not symbols) as the input, and relies on knowing the counts, and you are happy to pass in the counts to the decoding, but for some reason that I do not understand, you refuse to permit the decoding to use the information that would permit it to convert back from symbol numbers to symbols. Because of your refusal, it was necessary to make the symbol numbers the same as the symbols, which forces the encoding to emit a sequence about twice as large as it could be. If you would permit the alphabet variable to be used in the decoding then arithmetic encoding would be more efficient.
Yusuf lamah
on 25 Mar 2020
how i can can display many figure and there histogram in one graph for easy comparison
See Also
Categories
Find more on Large Files and Big Data in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!