huff2mat.m

来自「jpeg在matlab下的仿真实现」· M 代码 · 共 34 行

M
34
字号
function x = huff2mat(y)

if ~isstruct(y) | ~isfield(y, 'min') | ~isfield(y, 'size') | ...
        ~isfield(y, 'hist') | ~isfield(y, 'code')
   error('The input must be a structure as returned by MAT2HUFF');
end
sz = double(y.size);  m = sz(1);  n = sz(2);
xin = double(y.min) - 32768;     
map = huffman(double(y.hist));

code = cellstr(char('' ,'0', '1' ));
link = [2; 0; 0]; left = [2 3];
found = 0; tofind = length(map);

while length(left) & (found < tofind)
    look = find(strcmp(map, code{left(1)}));
    if look
        link(left(1)) = -look;
        left = left(2:end);
        fount = fount + 1;
    else
        len = length(code);
        link(left(1)) = len + 1;
        link = [link; 0; 0];
        code(end + 1) = strcat(code{left(1)}, '0');
        code(end + 1) = strcat(code{left(1)}, '1');
        left = left(2:end); 
        left = [left len + 1 len + 2];
    end
end
x:unravel(y.code', link, m * n);
x:x + xmin - 1;
x:reshape(x, m, n);
   

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?