实验三图像压缩编码技术_第1页
实验三图像压缩编码技术_第2页
实验三图像压缩编码技术_第3页
实验三图像压缩编码技术_第4页
实验三图像压缩编码技术_第5页
已阅读5页,还剩17页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

太原理工大学现代科技学院

数字图像处理课程试验汇报

专业班级—a控1/4

学号

姓名杨东倡

指导教师刘帆

试验名称试验三、图像压缩编码技术同组人

专业班级测控14-4姓名杨东倡学号—成绩

试验三、图像压缩编码技术

一、试脸目的

1.理解有损压缩和无损压缩的概念;

2.理解图像压缩的重要原则和目的$

3.理解几种常用B勺图像压缩编吗方式;

4.运用MATLAB程序进行图像压缩编码。

二、试脸原理

L图像压缩原理

图像压缩重要目口勺是为了节省存储空间,增长传播速度。图像压缩的理想原则是信息丢失至少,压

缩比例最大。不损失图像质量的压缩称为无损压缩,无损压缩不也许抵达很高口勺压缩比;损失图像质

量的压缩称为有损压缩,高E向压缩比是以牺牲图像质量为代价的。压缩的实现措施是对图像重新进行

编码,但愿用更少的数据体现图像。

信息的冗余量有许多种,如空间冗余,时间冗余,构造冗余,知识冗余,视觉冗余等,数据压缩实质上

是减少这些冗余量。高效编码的重要措施是尽量清除图像中的冗余成分,从而以最小的码元包括最大

本试验重要运用MATLAB程序进行赫夫曼(Huffman)编码和行程编码(RunLengthEncoding,RLE)。

三、试脸内容

1.实现基本JPEG的压缩和编码分三个环节:

(1)首先通过DCT变换清除数据冗余;

(2)使用量化表对DCT系数进行量化:

(3)对量化后的系数进行Huffman编码。

四、试脸环节

1打开计算机,启动MATLAB程序;

2选择一幅图像,并进行赫夫曼和行程编码压缩处埋;

3将原图像在Photoshop软件中打开,分别以不同样的位图文献格式进行“另保留”,比较它们H勺数据

量。

4记录和整顿试验汇报

Untitled.m

clear

loadwoman;

%X=imread('girl.bmp*,*bmp');

data=uint8(X);

[zipped,info]=huffencode(data);

unzipped=huffdecode(zipped,info,data);

subplot(121);imshow(data);

subplot(122);imshow(unzipped);

erms=compare(data(:),unzipped(:))

cr=info.ratio

whosdataunzippedzipped

huffencode.m

function[zipped,info)-huffencode(vector)

if~isa(vector,'uint8')

error('inputargumentmustbeauint8vector');

end

[m,n]=size(vector);

vector=vector(:)1;

f=frequency(vector);symbols=find(f-=0);

f=f(symbols);

[f,sortindex]=sort(f);symbols=symbols(sortindex);

len=length(symbols);

symbols_index=num2cell(1:len);

codeword_tmp=cell(len,1);

whilelength(f)>1

indexl=symbols_index{1};

index2=symbols_index{2};

codeword_tmp(indexl)=addnode(codev?ord_tmp(indexl),uint8(0));

codeword_tmp(index2)=addnode(codevzord_tmp(index2),uint8(1));

f=[sum(f(1:2))f(3:end)];

symbols_index=[{[indexl,index2]}symbols_index(3:end)];

[f,sortindex]=sort(f);

symbols_index=symbols_index(sortindex);

end

codeword=cell(256,1);

codeword(symbols)=codeword_tmp;

len=O;

forindex=l:length(vector)

•len=len+length(codev/ord{double(vector(index))+1});

•end

string=repmat(uint8(0),1,len);

pointer=l;

:forindex=l:length(vector)

IT

:code=codeword{double(vector(index))+1);

len=length(code);

string(pointer+(0:len-1))=code;

:pointer=pointer+len;

:end

len=length(string);

pad=8-mod(len,8);

ifpad>0

string=[stringuint8(zeros(1,pad))];

end

codeword=codeword(symbols);

codelen=zeros(size(codeword));

weights=2.A(0:23);

maxcodelen=0;

forindex=l:length(codeword)

len=length(codeword!index});

iflen>maxcodelen

maxcodelen=len;

end

iflen>0

code=sum(weights(codeword{index}==1));

code=bitset(code,len+1);

codeword!index}=code;

codelen(index)=len;

end

end

codeword=[codeword!:}];

cols=length(string)/8;

string=reshape(string,8,cols);

weights=2.A(0:7);

zipped=uint8(weights*double(string));

huffcodes=sparse(1,1);

forindex=l:nnz(codeword)%length(codeword)%numel(codeword)

huffcodes(codevzord(index),1)=symbols(index);

end

info.pad=pad;

info.huffcodes=huffcodes;

info.ratio=cols./length(vector);

info.length=length(vector);

info.maxcodelen=maxcodelen;

info.rows=m;

订info.cols=n;

huffdecode.m

functionvector=huffdecode(zipped,info,image)

if-isa(zipped,*uint8')

error('inputargumentmustbeauint8vector');

end

len=length(zipped);

string=repmat(uint8(0),1,len.*8);

bitindex=l:8;

forindex=l: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.A(0:51);

vector=repmat(uint8(0),1,info.length);

vectorindex=l;

codeindex=l;

code=0;

forindex=l:len

code=bitset(code,codeindex,string(index));

codeindex=codeindex+l;

byte=decode(bitset(code,codeindex),info);

ifbyte>0

vector(vectorindex)=byte-l;

codeindex=l;

code=0;

vectorindex=vectorindex+l;

end

end

vector=reshape(vector,info.rows,info.cols);

addnode.m

functioncodewordnew=addnode(codewordold,item)

codewordnew=cell(size(codewordold));

forindex=l:length(codeword_old)

codewordnew{index}=(item

codewordold(index}];

end

frequency.m

装functionf=frequency(vector)

if~isa(vector,*uint8')

error('inputargumentmustbeauint8vector');

end

f=repmat(0,1,256);

len=length(vector);

forindex=0:255

f(index+1)=sum(vector==uint8(index));end

线f=f./len;

decode.m

functionbyte=decode(code,info)

byte=info.huffcodes(code);

compare.m

functionerms=compare(fl,f2)

e=double(fl)-double(f2);

[m,n]=size(e);

erms=sqrt(sum(e(:).人2)/(m*n));

iferms~=0

emax=max(abs(e(:)));

[h,x]=hist(e(:));

iflength(h)>=1

figure(4)

bar(x,h,'k');

e=mat2gray(e,[-emax,emax]);

figure(5);

imshow(e);

end

end

CommandWindow

»Untitled

ems-

0

cr=

装0.6291

NameSizeByteaClassAttributes

daca256x25665536ulnce

unzipped256x25665536uint8

zipped1x4122641226uinc8

A»I

线

FileEditViewInsertToolsDesktopWindowHelp

DEUG%,丹@安居,国口园■国

[Untitled.m*]RLEncode.mxRLEdecode.mxcorrpare.mxUntitled5*义

1-clearall;

2-I=imread('C:\Users\a\Desktop\barbara.bmp');

3-[zipped,info]=RLEncode(I);

4-unzipped=RLEde|3ode(zipped,info)

5-subplot(121);imshow(I);

6-subplot(122);imshow(unzipped);

7-erms=con^>are(1(:),unzipped(:))

8-cr=info.ratio

9-whosIunzippedzipped

Untitled.mx[RLEncode.mx)RLEdecode.mxcompare.mxUntitled5*x

1function[zipped,info]=RLEncode(vector)

2-[m,n]=size(vector);

3-vector=vector(:)';

4-vector=uint8(vector(:));

5-L=length(vector);

6-c=vector(1);e(lfl)=c;e(l,2)=0;

7-tl=l

8-[forj=l:L

9-if((vector(j)==c))

10-e(tlz2)=double(e(tlr2)|)+l;

11-else

12-c=vectcr(j);

13-cl=cl+l;

14~e(cl,l)=c;

15-e(tlz2)=l;

16-end

17-end

18-zipped=e;

19-info.rows=m;

20-info.cols=n;

21-[m/n]=size(e);

22-info.ratio=m*n/(info.rows*info•cols);

Untitled.mxRLEncode.rrx|RLEdecode.mx]compare.mxUntitled5*x

1□functionunzipped=RLEde|code(zip,info)

2-zip=uint8(zip);

3-[m,n]=size(zip);

4—unzipped=[]

5-fori=l:m

6-section=repmat(zip(ir1),1,double(zip(i,2)));

7-unzipped=[unzippedsection];

8-end

9-unzipped=reshape(unzipped,info.rows,info.cols)

装10

Untitled.mxRLEncode.rrixRLEdecode.mx|compare.mx|Untitled5*x

□functionerms=conipare(fl,f2)

2-e=double|(f1)-double(f2);

3-[m,n]=size(e);

4—erirL3=sqrt(sum(e(:)2/(m*n)));

5

■commandWindowI

JLOUJL4O一J.——c一二一X^2Z7X*3Z7JLJL/xooXX7XX7--JO7XX/xoo

149149149162117149117117117877414911774149162

1361621361301231177411713687105149149105117180

117149105871491177411714913087149162149105162

11711710587149149105130180149105117180162105149

105149117105162180117105162180130105162180130117

130180162117136173162136117180162105130180149105

117162180130105162167130117149180149105149162149

1051491621671171

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论