版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
第PAGE第7页,共7页【】clear 1【】allfprintf('Readingdata...')data=imread('cameraman.tif');data=uint8(data);%读入数据,并将数据限制为uint8fprintf('Done!\n')%编码紧缩fprintf('compressingdata...');[zipped,info]=norm2huff(data);fprintf('Done!\n')%解紧缩fprintf('compressingdata...');unzipped=huff2norm(zipped,info);fprintf('Done!\n')%测试是否无掉真isOK=isequal(data(:),unzipped(:))%显示紧缩后果whosdatazippedunzippedfunction[zipped,info]=norm2huff(vector)if~isa(vector,'uint8'),error('inputargumentmustbeauint8vector')endvector=vector(:)';%将输入向量转换为行向量f=frequency(vector);%盘算个元素消失的概率simbols=find(f~=0);f=f(simbols);%将元素按消失的概率分列[f,sortindex]=sot(f);simbols=simbols(sortindex);%产生码字generatethecodewordasthe52bitsofadoublelen=length(simbols);simbols_index=num2cell(1:len);codeword_tmp=cell(len,1);whilelength(f)>1,index1=simbols_index{1};index2=simbols_index{2};codeword_tmp(index1)=addnode(codeword_tmp(index1),uint8(0));codeword_tmp(index2)=addnode(codeword_tmp(index2),uint8(1));f=[sum(f(1:2))f(3:end)];simbols_index=[{[index1index2]}simbols_index(3:end)];resortdatainordertohavetwonodeswithlowerfrequencyasfirstto[f,sortindex]=sort(f);simbols_index=simbols_index(sortindex);end%对应响应的元素与码字codeword=cell(256:1);codeword(simbols)=codeword_tmp;%盘算总的字符串长度len=0;forindex=1:length(vector),len=len+length(codeword{double(vector(index))+1});end%产生01序列string=repmat(uint8(0),1,len);pointer=1;forindex=1:length(vector),code=codeword{double(vector(index))+1};len=length(code);string(pointer+(0:len-1))=code;pointer=pointer+len;endpad>0,string=[stringuint8(zeros(1,pad))];end%保管现实有效的码字codeword=codeword(simbols);codelen=zeros(size(codeword));weights=2.^(0:23);maxcodelen=0;forindex1:length(codeword),len=length(codeword{index});iflen>maxcodelen,maxcodelen=len;endiflen>0,code=sum(weights(codeword{index}==1));code=bitset(code,len+1);codeword{index}=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);%initsparsematrixforindex=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;functioncodeword_new=addnode(codeword_old,item)codeword_new=cell(size(codeword_old));forindex=1:length(codeword_old),codeword_new{index}=[itemcodeword_old{index}];endfunctionvector=huff2norm(zipped,info)%HUFF2NORMHuffman解码器%HUFF2NORM(X,INFO)依据信息体构造info返回向量zipped的解码成果%%矩阵参数以X(:)情势输入if~isa(zipped,'uint8'),error('inputargumentmustbeauint8vector')end%产生01序列len=length(zipped);string=repmat(uint8(0),1,len.*8);bitindex=1:8;forindex+1:len,string(bitindex+8.*(index-1))=uint8(bitget(zipped(index),bitindex));end%调剂字符串string=logical(string(:)');%remove0paddinglen=length(string);%解码weights=2.^(0:51);vector=repmat(uint8(0),1,info,length);vectorindex=1;codeindex=1;code=0;forindex=1:len,code=bitset(code,codeindex,string(index));]codeindex=codeindex+1;byte=decode(bitset(code,codeindex),info);ifbyte>0,%vector(vectorindex)=byte-1;codeindex=1;code=0;vectorindex=vectorindex+1;endendfunctionbyte=decode(code,info)byte=info.huffcodes(code);functionf=frequency(vector)%FREQUENCY盘算元素消失概率if~isa(vector
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 思南县县直机关事业单位考调工作人员笔试真题及答案
- 泉州南安市侨光中学教师招聘考试真题2025
- 临床偏瘫患者温柔治疗姿势要点
- 骨质疏松性骨折手术治疗
- 介入医联体区域诊疗协同发展
- 儿童泌尿系统感染抗菌药物策略2026
- 《铁路桥梁施工与维护(第2版)》课件 项目2 桥梁基础构造与施工
- 5月眼科护理月度考试试卷
- 急救药品管理制度试题及答案范文
- 2026毕业生设计面试题及答案
- (2026版)《煤矿重大事故隐患判定标准》培训课件
- 2026信息安全行业市场发展分析及前景趋势与投融资发展机会研究报告
- 2025年湖北省中考生物、地理合卷试卷真题(含答案)
- 普外科常见病
- 卒中管理及中心建设
- 电阻的星形连接和三角形连接
- 中华人民共和国尘肺标准片
- 第三次国土调查数字正射影像生产技术设计书
- 教育部高中语文新课程标准
- 危险化学品MSDS(碳酸钙)
- 2022年新《噪声污染防治法》亮点解读课件
评论
0/150
提交评论