资源描述:
《数字图像处理实验6冈萨雷斯.doc》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、一、实验目的实验六图像压缩(同预习)1、理解有损压缩和无损压缩的概念;2、理解图像压缩的主要原则和目的;3、利用MATLAB程序进行图像压缩。二、实验内容1、Huffman编码使用mat2huff,huff2mat实现Huffman编解码,并应用imratio计算编码后信号的压缩率。2、编写无损预测编解码(losslesspredictivecoding)程序,使p313Figure8.7(c图具有更低的熵(5.4436)。显示预测误差(predictionerror图。用解码程序解码,并验证解码是否正确(compare)。3、
2、参考p319-323,实现16×16分块离散余弦(DCT编码,用zigzag方式保留每一块的前10个和前21个系数,再进行进行DCT解码。编写程序并分别显示解码后的两个图。实验程序:实验1:i=imread('Fig0804(a(Tracy.tif';i1=mat2huff(i;cr1=imratio(i,i1;%cr1,压缩率i2=huff2mat(i1;rmse1=compare(i,i2;figure,imshow(i;figure,imshow(i2;实验2:子程序1:functiony=mat2lpc2(x,f%本程序
3、改自课本上那个程序,可实现更高压缩率!error(nargchk(1,2,nargin;%Checkinputargumentsifnargin<2%Setdefaultfilterifomittedf=1;endx=double(x;%Ensuredoubleforcomputations[m,n]=size(x;%Getdimensionsofinputmatrixp=zeros(m,n;%Initlinearpredictionto0xs=x;zc=zeros(1,n;%Prepareforinputshiftandpad
4、forj=1:length(f%Foreachfiltercoefficient...xs=[zc;xs(1:end-1,:];%Shiftandzeropadxga改加一行p=p+f(j*xs;%Formpartialpredictionsumsendy=x-round(p;%Computethepredictionerror子程序2:functionx=lpc2mat2(y,f%本程序改自课本上那个程序,可以解压error(nargchk(1,2,nargin;%Checkinputargumentsifnargin<2%S
5、etdefaultfilterifomittedf=1;endy=y';f=f(end:-1:1;%Reversethefiltercoefficients[m,n]=size(y;%Getdimensionsofoutputmatrixorder=length(f;%Getorderoflinearpredictorf=repmat(f,m,1;%Duplicatefilterforvectorizingx=zeros(m,n+order;%Padfor1st'order'columndecodes%Decodetheoutp
6、utonecolumnatatime.Computeapredictionbased%onthe'order'previouselementsandaddittotheprediction%error.Theresultisappendedtotheoutputmatrixbeingbuilt.forj=1:njj=j+order;x(:,jj=y(:,j+round(sum(f(:,order:-1:1.*...x(:,(jj-1:-1:(jj-order,2;endx=x(:,order+1:end;%Removeleftp
7、addingx=x';总程序:f=imread('Fig0807(c(Aligned.tif';e=mat2lpc2(f;figure,imshow(mat2gray(e;h=entropy(e;c=lpc2mat2(e;figure,imshow(c,[];rmse=compare(f,c;实验三:i=imread('Fig0804(a(Tracy.tif';i=im2double(i;mask1=[1111000000000000111000000000000011000000000000001000000000000000
8、00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000