下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、clear allfprintf( Reading data 、 ) data=imread( cameraman 、 tif );data=uint8(data); %读入数据 , 并将数据限制为 uint8 fprintf( Done!n )%编码压缩fprintf( compressing data 、 ); zipped,info=norm2huff(data);fprintf( Done!n ) %解压缩fprintf( compressing data 、 ); unzipped=huff2norm(zipped,info);fprintf( Done!n ) %测试就是否无失真
2、isOK=isequal(data(:),unzipped(:) %显示压缩效果 whos data zipped unzipped function zipped,info=norm2huff(vector) if isa(vector, uint8 ),error( input argument must be a uint8 vector ) end vector=vector(:);%将输入向量转换为行向量 f=frequency(vector);%计算个元素出现的概率 simbols=find(f=0);f=f(simbols); %将元素按出现的概率排列 f,sortindex=s
3、ot(f);simbols=simbols(sortindex);%产生码字 generate the codeword as the 52 bits of a double len=length(simbols);simbols_index=num2cell(1:len); codeword_tmp=cell(len,1);while length(f)1,index1=simbols_index1;index2=simbols_index2; codeword_tmp(index1)=addnode(codeword_tmp(index1),uint8(0); codeword_tmp(i
4、ndex2)=addnode(codeword_tmp(index2),uint8(1);f=sum(f(1:2) f(3:end);simbols_index=index1 index2 simbols_index(3:end);%将数据重新排列 , 就是两个节点的频率尽量与前一个节点的频率想当asresort data in order to have two nodes with lower frequency first to f,sortindex=sort(f);simbols_index=simbols_index(sortindex);end%对应相应的元素与码字 codewo
5、rd=cell(256:1); codeword(simbols)=codeword_tmp;%计算总的字符串长度len=0;for index=1:length(vector),len=len+length(codeworddouble(vector(index)+1); end%产生 01序列 string=repmat(uint8(0),1,len);pointer=1;for index=1:length(vector),code=codeworddouble(vector(index)+1; len=length(code);string(pointer+(0:len-1)=code
6、;pointer=pointer+len;end%如果需要 , 加零 len=length(string); pad=8-mod(len,8);if pad0,string=string uint8(zeros(1,pad);end%保存实际有用的码字 codeword=codeword(simbols); codelen=zeros(size(codeword);weights=2、人(0:23);maxcodelen=0;for index 1:length(codeword), len=length(codewordindex);if lenmaxcodelen,maxcodelen=l
7、en;end if len0,code=sum(weights(codewordindex=1); code=bitset(code,len+1);codewordindex=code;codelen(index)=len;endendcodeword=codeword:%计算压缩后的向量cols=length(string)/8; string=reshape(string,8,cols);weights=2、人(0:7);zipped=uint8(weights*double(string);%存储一个稀疏矩阵huffcodes=sparse(1,1); % init sparse mat
8、rixfor index=1:numel(codeword), huffcodes(codeword(index),1)=simbols(index);end%产生信息结构体info 、 pad=pad;info 、 ratio=cols 、 /length(vector);info 、 length=length(vector);info 、 maxcodelen=maxcodelen;function codeword_new=addnode(codeword_old,item) codeword_new=cell(size(codeword_old);for index=1:length
9、(codeword_old),codeword_newindex=item codeword_oldindex;endfunction vector=huff2norm(zipped,info)%HUFF2N0RM Huffma 解码器%HUFF2N0RM(X,INF根据信息体结构info 返回向量zipped的解码结果%矩阵参数以 X(:) 形式输入if isa(zipped, uint8 ),error( input argument must be a uint8 vector)end%产生 01序列len=length(zipped);string=repmat(uint8(0),1,
10、len 、 *8);bitindex=1:8;for index+1:len,string(bitindex+8 、 *(index-1)=uint8(bitget(zipped(index),bitindex);end%调整字符串string=logical(string(:);% remove 0 paddinglen=length(string);%解码weights=2、A(0:51);vector=repmat(uint8(0),1,info,length);vectorindex=1;codeindex=1;code=0;for index=1:len,code=bitset(co
11、de,codeindex,string(index);codeindex=codeindex+1; byte=decode(bitset(code,codeindex),info);if byte0, %vector(vectorindex)=byte-1; codeindex=1;code=0;vectorindex=vectorindex+1;endendfunction byte=decode(code,info) byte=info 、 huffcodes(code);function f=frequency(vector)%FREQUENCY算元素出现概率if isa(vector, u
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 结构增强用纺织品市场发展预测和趋势分析
- 耐磨试验机产品市场环境与对策分析
- 输注延长管市场发展预测和趋势分析
- 电火花成型机床产品市场需求分析报告
- 神经外科手术器械产品原材料供应与需求分析
- 输送机保护装置产品市场需求分析报告
- 自行车锁产品营销计划书
- 闭式塔市场洞察报告
- 电源模块产品市场需求分析报告
- 高性能传输线缆产品营销计划书
- 《餐饮培训资料》课件
- 拌和站迎检策划方案
- 胃排空障碍护理课件
- 《水浒传》人物分析课件
- 《金融风险管理》 课件全套 (殷平生)第1-12章 金融风险管理概述-大数据发展与金融风险管理
- 腕关节神经压迫研究
- 银行客户经理营销技巧培训
- 【施工组织设计】内容完整性和编制水平
- 跨部门工作联络单
- 第1单元 神州古韵-《梅花三弄》课件 2022-2023学年粤教版初中音乐八年级下册
- 山东黄金集团有限公司省内井下一线产业工人招聘笔试试题及答案2021
评论
0/150
提交评论