- your list of probabilities does not sum to unity
- your list of symbols is not the same length as the corresponding list of probabilites
Help on how to achieve lossless image compression using arithmetic encoding and decoding.
13 ビュー (過去 30 日間)
古いコメントを表示
Had this error after passing the coefficients of wavelet image tranform, symbols and probability to the package
Arithmetic Encoding & Decoding
Error:
[Tag_bits]= Arithmetic_enc(sym,p,c);
Plese enter proper values!!!
Elapsed time is 0.000439 seconds.
Output argument "Tag_bits" (and possibly others) not assigned a value in the execution with "Arithmetic_enc" function.
code:
function Tag_bits =Arithmetic_enc(sym,p,seq)
tic; % TIC-TOC commands are used to measure the simulation time of the program.
format long g;
%% ARGUMENTS OF THE FUNCTION
% SYM is a string of symbols of information from the source.
% P represents the array of Probabilities of the corresponding symbols in
% the SYM string.
% SEQ is the string of sequence of symbols to be encoded by arithmetic
% coding.
if(length(sym)==length(p) && sum(p)==1)
%% ALGORITHM IMPLEMENTATION
% Calculate the Symbol Intervals.
Fx=zeros(1,length(sym));
for i=1:length(sym)
if i==1
Fx(i)=p(i);
else
Fx(i)=Fx(i-1)+p(i);
end
end
% Encoding the Sequence of Symbols.
L=0;U=1; % Initial Lower and Upper Intervals.
Tag_bits=zeros(1,0); % Initializing the Tag Bits.
for i=1:length(seq)
j=find(seq(i)==sym); % Finds the Index of the sequence symbol in the symbol string.
if(j==1)
L_new=L;
else
L_new=L+(U-L)*Fx(j-1);
end
U_new=L+(U-L)*Fx(j);
L=L_new;
U=U_new;
while((L<0.5 && U<0.5) ||(L>=0.5 && U>0.5))
if(L<0.5 && U<0.5)
Tag_bits=[Tag_bits,'0'];
L=2*L;
U=2*U;
else
Tag_bits=[Tag_bits,'1'];
L=2*(L-0.5);
U=2*(U-0.5);
end
end
end
tag=(L+U)/2;
% Embedding the Final Tag Value.
bits=zeros(1,0);
if(2*tag>1)
tag=2*tag-1;
bits=[bits,'1'];
else
tag=2*tag;
bits=[bits,'0'];
end
while(bin2dec(bits)/2^length(bits)<L)
if(2*tag>1)
tag=2*tag-1;
bits=[bits,'1'];
else
tag=2*tag;
bits=[bits,'0'];
end
end
Tag_bits=[Tag_bits,bits];
% Padding of zeros is done to keep the TAG BITS size multiple of 16 bits.
Tag_bits=[Tag_bits,dec2bin(0,16-rem(length(Tag_bits),16))];
display('Tag Value is:');
disp(bin2dec(Tag_bits)/2^length(Tag_bits));
display('Tag Word is:');
Tag_bits=[Tag_bits,dec2bin(length(seq),16)];
else
display('Plese enter proper values!!!');
end
toc;
workspace values for
seq = c
c= 1x349184 double
p = 1x349118 double
sym = 1x349118 double
sum(p)
ans = 0.999999999999999
Help on how to achieve lossless image compression with any other package or this package for arithmetic encoding and decoding.
2 件のコメント
DGM
2023 年 9 月 18 日
編集済み: DGM
2023 年 9 月 18 日
Since we don't know how you tried to call the function, we don't know whether any other suggestion would work either. All we know is that one of the following is true:
If it's the first case, there might be room for float rounding errors to cause problems there.
Documentation on this FEX submission could be better.
回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Denoising and Compression についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!