Huffman dictionary provided does not have the codes for all the input signals
3 次查看(过去 30 天)
显示 更早的评论
I seem to be having a problem passing the string and dictionary through the huffmanenco function. I've tried almost everything, but the I keep getting the error that the Huffman dictionary does not have all the input codes. Yet I'm positive it does.
%%HUFFMAN TEST
clear all; close all; clc;
sig = ['a'; 'b'; 'c'; 'd'; 'e'; 'f'; 'g'; 'h'; 'i'; 'j';...
'k'; 'l'; 'm'; 'n'; 'o'; 'p'; 'q'; 'r'; 's'; 't';...
'u'; 'v'; 'w'; 'x'; 'y'; 'z'; ':'; ' '; ','; '.'];
% Get probability
char_count = zeros(30,1);
for i = 1:30
for c = sig(i)
char_count(i,1) = length(find(sig == c));
end
end
sym_prob = char_count / sum(char_count);
% Huffman Dictionary
% symbols = cellstr(symbols); % Still doesn't work in huffmandict, so try manually typing out again with curly braces
sig = {'a'; 'b'; 'c'; 'd'; 'e'; 'f'; 'g'; 'h'; 'i'; 'j';...
'k'; 'l'; 'm'; 'n'; 'o'; 'p'; 'q'; 'r'; 's'; 't';...
'u'; 'v'; 'w'; 'x'; 'y'; 'z'; ':'; ' '; ','; '.'};
[dict, aveLength] = huffmandict(sig, sym_prob);
% Process signal
str = 'A technique is developed to construct a representation of planar objects undergoing a general affine transformation. The representation can be used to describe planar or nearly planar objects in a three-dimensional space, observed by a camera under arbitrary orientations.';
str_int = bin2dec(dec2bin(str));
sig = cell(size(str));
for i = 1:length(str)
sig{i} = char(str_int(i));
end
% Encode & Decode
sig_enco = huffmanenco(sig, dict);
dsig = huffmandeco(sig_enco, dict);
0 个评论
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Source Coding 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!