实验三 图像编码.docx

上传人:b****1 文档编号:3407543 上传时间:2023-05-05 格式:DOCX 页数:12 大小:698.40KB
下载 相关 举报
实验三 图像编码.docx_第1页
第1页 / 共12页
实验三 图像编码.docx_第2页
第2页 / 共12页
实验三 图像编码.docx_第3页
第3页 / 共12页
实验三 图像编码.docx_第4页
第4页 / 共12页
实验三 图像编码.docx_第5页
第5页 / 共12页
实验三 图像编码.docx_第6页
第6页 / 共12页
实验三 图像编码.docx_第7页
第7页 / 共12页
实验三 图像编码.docx_第8页
第8页 / 共12页
实验三 图像编码.docx_第9页
第9页 / 共12页
实验三 图像编码.docx_第10页
第10页 / 共12页
实验三 图像编码.docx_第11页
第11页 / 共12页
实验三 图像编码.docx_第12页
第12页 / 共12页
亲,该文档总共12页,全部预览完了,如果喜欢就下载吧!
下载资源
资源描述

实验三 图像编码.docx

《实验三 图像编码.docx》由会员分享,可在线阅读,更多相关《实验三 图像编码.docx(12页珍藏版)》请在冰点文库上搜索。

实验三 图像编码.docx

实验三图像编码

实验三图像编码

一实验目的

1.从编码原理的角度出发,了解图像压缩编码的分类方法。

2.掌握算术编码、预测编码和行程编码的图像压缩编码原理,编程实现各个算法,并比较原始图像和解码图像。

3.掌握变换编码的基本原理。

二实验原理

三实验内容

(编写MATLAB文件,要求调试通过,并给出程序清单及代码各个部分的说明,源代码中主要的变量、函数、循环结构等要有注释。

1.算术编码

clearall

formatlonge;

symbol=['abcd'];

ps=[0.40.20.10.3];

inseq=('dacab');

codeword=suanshubianma(symbol,ps,inseq)

outseq=suanshujiema(symbol,ps,codeword,length(inseq))

functionacode=suanshubianma(symbol,ps,inseq)

high_range=[];

fork=1:

length(ps)

high_rabge=[high_rangesum(ps(1:

k))];

end

low_range=[0high_range(1:

length(ps-1))];

sbidx=zeros(size(inseq));

fori=1:

length(inseq)

sbidx(i)=find(symbol==inseq(i));

end

low=0;

high=1;

fori=1:

length(inseq)

range=high-low;

high=low+range*high_range(sbidx(i));

low=low+range*low_range(sbidx(i));

end

acode=low;

functionsymbos=suanshujiema(symbol,ps,codeword,symlen)

formatlonge

high_range=[];

fork=1:

length(ps)

high_range=[high_rangesum(ps(1:

k))];

end

low_range=[0high_range(1:

length(ps)-1)];

psmin=min(ps);

symbos=[];

fori=1:

symlen

idx=max(find(low_range<=codeword));

codeword=codeword-low_range(idx);

ifabs(codeword-ps(idx))<0.01*psmin

idx=idx+1;

codeword=0;

end

symbos=[symbossymbol(idx)];

codeword=codeword/ps(idx);

ifabs(codeword)<0.01*psmin

i=symlen+1;

end

end

运行结果:

2.预测编码

X=imread('peppers.bmp,bmp');

imshow(X)

title('原始图象')

X=double(X)

Y=Yucejiema(X)

XX=Yucejiema(Y)

fiqure,imshow(mat2gray(Y));

title('预测误差图象')

e=double(X)-double(XX);

[m,n]=size(e);

erms=sqrt(sum(e(:

).^2)/(m*n));

[h,x]=hist(X(:

));

figure;bar(x,h,'k');

title('原图直方图')

[h,x]=hist(Y(:

));

figure:

bar(x,h,'k');

title('预测误差直方图')

XX=uint8(XX);

figure,imshow(XX);

title('解码图象')

 

functionY=Yucebianma(x,f)

error(nargchk(1,2,nargin))

ifnargin<2

f=1;

end

x=double(x);

[m,n]=size(x);

p=zeros(m,n);

xs=x;

zc=zeros(m,1);

forj=1:

length(f)

xs=[zcxs(:

1:

end-1)];

p=p+f(j)*xs;

end

Y=x-round(p);

 

functionx=Yucejiema(Y,f)

error(nargchk(1,2,nargin));

ifnargin<2

f=1;

end

f=f(end:

-1:

1);

[m,n]=size(Y);

order=length(f);

f=repmat(f,m,1);

x=zeros(m,n+order);

forj=1:

n

jj=j+order;

x(:

jj)=Y(:

j)+round(sum(f(:

order:

-1:

1).*x(:

(jj-1):

-1:

(jj-order)),2));

end

x=x(:

.order+1:

end);

 

3.行程编码

clearall

IY=imread('couple.bmp');

I=im2bw(IY,0.35);

[zipped,info]=Xingchengbianma(I);

unzipped=Xingchengjiema(zipped,info);

imshow(IY);

title

figure;imshow(I);

title

figure;imshow(unzipped);

title

unzipped=uint8(unzipped);

erms=jfwucha(I(:

),unzipped(:

))

cr=info.ratio

whosIYIunzippedzipped

function[zipped,info]=Xingchengbianma(vector)

[m,n]=size(vector);

vector=vector(:

);

vector=uint8(vector(:

));

L=length(vector);

c=vector

(1);

e(1,1)=c;

e(1,2)=0;

t1=1;

forj=1:

L

if((vector(j)==c))

e(t1,2)=double(e(t1,2))+1;

else

c=vector(j);

t1=t1+1;

e(t1,1)=c;

e(t1,2)=1;

end

end

zipped=e;

info.rows=m;

info.cols=n;

[m,n]=size(e);

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

functionunzipped=Xingchengjiema(zip,info)

zip=uint8(zip);

[m,n]=size(zip);

unzipped=[];

fori=1:

m

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

unzipped=[unzippedsection];

end

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

unzipped=double(unzipped);

functionerms=jfwucha(f1,f2)

e=double(f1)-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

 

运行结果:

erms=

0

 

cr=

6.436157226562500e-002

NameSizeBytesClass

I256x25665536logicalarray

IY256x25665536uint8array

unzipped256x25665536uint8array

zipped2109x24218uint8array

Grandtotalis200826elementsusing200826bytes

 

erms=

0

 

cr=

6.436157226562500e-002

NameSizeBytesClass

I256x25665536logicalarray

IY256x25665536uint8array

unzipped256x25665536uint8array

zipped2109x24218uint8array

Grandtotalis200826elementsusing200826bytes

四实验分析

1.在图像的预测编码方法中,有哪些常见的线性预测方案?

2.行程编码常常应用在哪些场合?

3.在变换编码方法中,压缩是在变换步骤中取得的吗?

解释说明原因。

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > IT计算机 > 电脑基础知识

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2