实验三 图像编码.docx
- 文档编号:10058923
- 上传时间:2023-02-08
- 格式:DOCX
- 页数:12
- 大小:698.40KB
实验三 图像编码.docx
《实验三 图像编码.docx》由会员分享,可在线阅读,更多相关《实验三 图像编码.docx(12页珍藏版)》请在冰豆网上搜索。
实验三图像编码
实验三图像编码
一实验目的
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.在变换编码方法中,压缩是在变换步骤中取得的吗?
解释说明原因。
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 实验三 图像编码 实验 图像 编码