Arithmetic coding explanation?

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

답변 (8개)

Walter Roberson
Walter Roberson 2012년 5월 19일

0 개 추천

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

Yusuf lamah
Yusuf lamah 2020년 2월 18일
thanks alot Walter Roberson for your always helping and suport, but how i can compute histc(), counts and what is the better in text copression huffman or arithmatic code
alphabet = unique(Input);
Counts = histc(Input, alphabet) ;
Walter Roberson
Walter Roberson 2020년 3월 14일
Arithmetic coding is more efficient than Huffman
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
slama najla 2012년 5월 20일
편집: Walter Roberson 2020년 3월 14일

0 개 추천

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);
Yusuf lamah
Yusuf lamah 2020년 3월 14일

0 개 추천

how to use counts in the following function ARITHENCO(SEQ, COUNTS)?

댓글 수: 16

alphabet = unique(Input);
Counts = histc(Input, alphabet) ;
Yusuf lamah
Yusuf lamah 2020년 3월 14일
thank you very much
Yusuf lamah
Yusuf lamah 2020년 3월 14일

my program error: (the symbol sequence parameter can take values only between 1 and the lenght of the symbol counts parameter) what mean please

[alphabet, ~, SEQ] = unique(Input);
COUNTS = histc(Input, alphabet);
arithenco(SEQ, COUNTS)
Yusuf lamah
Yusuf lamah 2020년 3월 14일
thanks alot my program good for coding but when i try to return the original message which was 'yusuf' and the code was dseq=arithdeco(code,counts,length (input)) the output was seq dont the input message how i can get the original message
alphabet(dseq)
There are techniques that can be used to encode the alphabet as part of the stream, but they are more advanced and not really relevant to you.
Yusuf lamah
Yusuf lamah 2020년 3월 15일
could i know how i can use arithmetic coding function in matlab arithenco & arithdeco for alphabets letters and english symbols
Yusuf lamah
Yusuf lamah 2020년 3월 17일
편집: Walter Roberson 2020년 3월 20일
text ='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 '
Walter Roberson
Walter Roberson 2020년 3월 17일
arithdeco can never return text.
Yusuf lamah
Yusuf lamah 2020년 3월 20일
how i can return text using dseq
text = 'yusuf lamah';
input = double(text);
counts = max(1,accumarray(input(:), 1));
code = arithenco(input, counts);
dseq = arithdeco(code, counts, length(input));
char(dseq)
This will not produce the optimal sequence: in fact the sequence it will produce will be more than twice as long as the optimal sequence. It does, however, satisfy your requirement that the text be created using arithdeco without using the much more efficient technique I already told you about, namely char(alphabet(dseq)) . I don't know why using char(alphabet(dseq)) is not acceptable to you, but whatever.
Yusuf lamah
Yusuf lamah 2020년 3월 22일
thank you very much Walter Roberson
Yusuf lamah
Yusuf lamah 2020년 3월 25일
how i can can display many figure and there histogram in one graph for easy comparisem
Walter Roberson
Walter Roberson 2020년 3월 25일
hold on
Or
subplot
Yusuf lamah
Yusuf lamah 2020년 3월 26일
thanks alot WalterRoberson
Yusuf lamah
Yusuf lamah 2020년 3월 26일
how i can use xlawrite funtion to save the results in specific sheet and specific table in the Excel

댓글을 달려면 로그인하십시오.

Yusuf lamah
Yusuf lamah 2020년 3월 22일

0 개 추천

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

Walter Roberson
Walter Roberson 2020년 3월 22일
https://www.mathworks.com/matlabcentral/answers/375213-how-can-replace-randi-instead-randint

댓글을 달려면 로그인하십시오.

Yusuf lamah
Yusuf lamah 2020년 3월 22일

0 개 추천

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

Walter Roberson
Walter Roberson 2020년 3월 22일
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
Yusuf lamah 2020년 3월 23일

0 개 추천

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

Walter Roberson
Walter Roberson 2020년 3월 23일
You are permitting Huffman to decode using the dictionary, which contains information about the bits and corresponding symbols. However you are not permitting arithdeco to access the list of symbols: you insisted that it had to be transformed into symbols directly from the arithdeco output. The only way to do that was to force the arithmetic encoding to be much less efficient than it should be in order to internally encode the dictionary.
Huffman would stop looking as efficient if you forced it to encode the dictionary in the data stream the same way you are forcing arithenco to do.
Yusuf lamah
Yusuf lamah 2020년 3월 23일
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
Walter Roberson 2020년 3월 23일
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
Yusuf lamah 2020년 3월 25일

0 개 추천

how i can can display many figure and there histogram in one graph for easy comparison
Yusuf lamah
Yusuf lamah 2020년 3월 26일

0 개 추천

thank you very much Walter Roberson

카테고리

질문:

2012년 3월 15일

댓글:

2020년 3월 26일

Community Treasure Hunt

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

Start Hunting!

Translated by