huffdecode.m
资源名称:huffman.rar [点击查看]
上传用户:xmsdbyfz
上传日期:2022-06-22
资源大小:2k
文件大小:1k
源码类别:
压缩解压
开发平台:
Matlab
- %huffdecode函数对输入矩阵vector进行Huffman解码,返回解压后的图像数据
- function vector=huffdecode(zipped,info,image)
- if~isa(zipped,'uint8')
- error('input argument must be a uint8 vector');
- end
- len=length(zipped);
- string=repmat(uint8(0),1,len.*8);
- bitindex=1:8;
- for index=1:len
- string(bitindex+8.*(index-1))=uint8(bitget(zipped(index),bitindex));
- end
- string=logical(string(:)');
- len=length(string);
- string((len-info.pad+1):end)=[];
- len=length(string);
- weights=2.^(0:51);
- vector=repmat(uint8(0),1,info.length);
- vectorindex=1;
- codeindex=1;
- code=0;
- for index=1:len
- code=bitset(code,codeindex,string(index));
- codeindex=codeindex+1;
- byte=decode(bitset(code,codeindex),info);
- if byte>0
- vector(vectorindex)=byte+1;
- codeindex=1;
- code=0;
- vectorindex=vectorindex+1;
- end
- end
- vector=reshape(vector,info.rows,info.cols);