图像的帧内预测编码设计内容:对一幅彩色或者灰度图像二维帧内预测编码,采用4阶线性预测器,根据最小均方误差原则(MMSE)设计预测器系数,并对预测误差进行量化处理,根据量化后的误差得到解码图像。设计目的:掌握图像的预测编解码的原理。课题要求:对任意大小的输入图像进行二维帧内预测编码,设计最佳预测器系数,比较不同图像预测器系数的共同点和不同点。对预测误差进行量化处理后,根据误差图像接到解码图像,对比图像质量,计算信噪比。以下是从网上找的clc;clearall;closeall;I2=imread('D:\MATLAB7\tuxiang\messi.bmp');%读入图片I=double(I2);%设定I是double类型fid=fopen('mydata.dat','w');[m,n]=size(I);J=ones(m,n);J(1:m,1)=I(1:m,1);J(1,1:n)=I(1,1:n);J(1:m,n)=I(1:m,n);%把I(1,1)赋值给J(1,1)J(m,1:n)=I(m,1:n);fork=2:m-1forl=2:n-1J(k,l)=I(k,l)-(I(k,l-1)/2+I(k-1,l)/4+I(k-1,l-1)/8+I(k-1,l+1)/8);%前值预测,J为要拿来编码传输的误差endendJ=round(J)cont=fwrite(fid,J,'int8');%解码cc=fclose(fid);fid=fopen('mydata.dat','r');I1=fread(fid,cont,'int8');tt=1;B=ones(m,n)forl=1:nfork=1:mB(k,l)=I1(tt);tt=tt+1;endendB=double(B);A=ones(m,n);A(1:m,1)=B(1:m,1);A(1,1:n)=B(1,1:n);A(1:m,n)=B(1:m,n);A(m,1:n)=B(m,1:n);fork=2:m-1forl=2:n-1A(k,l)=B(k,l)+(I(k,l-1)/2+I(k-1,1)/4+I(k-1,l-1)/8+I(k-1,l+1)/8);%endendcc=fclose(fid);A=uint8(A);subplot(2,2,1),imshow(I2);subplot(2,2,2),imshow(A);subplot(2,2,3),imshow(mat2gray(A)量化[m,n]=size(J);a=max(max(J));%求出这个矩阵的最大数字b=min(min(J));%求出矩阵最小数字c=20;%量化层数t=round((a-b)/c);%量化间隔forz=b:t:aforp=1:mforq=1:nif((J(p,q)z)&(J(p,q)=(z+t)))J(p,q)=(2*z+t)/2;endendendend信噪比%Matlab计算信噪比,程序如下functionsnr=SNR(I,In)%计算信号噪声比函数%byQulei%I:originalsignal%In:noisysignal(ie.originalsignal+noisesignal)%snr=10*log10(sigma2(I2)/sigma2(I2-I1))[row,col,nchannel]=size(I);snr=0;ifnchannel==1%grayimagePs=sum(sum((I-mean(mean(I))).^2));%signalpowerPn=sum(sum((I-In).^2));%noisepowersnr=10*log10(Ps/Pn);elseifnchannel==3%colorimagefori=1:3Ps=sum(sum((I(:,:,i)-mean(mean(I(:,:,i)))).^2));%signalpowerPn=sum(sum((I(:,:,i)-In(:,:,i)).^2));%noisepowersnr=snr+10*log10(Ps/Pn);endsnr=snr/3;end,