资源描述:
《基于块的全搜索运动估计算法实现matlab代码.docx》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、1.主文件motionEstAnalysis.m%ThisscriptusesalltheMotionEstimationalgorithmswrittenforthe%finalprojectandsavetheirresults.closeallclearall%imageName='caltrain.avi';VideoName='shaky_car.avi';video=aviread(VideoName);%movie(video);mbSize=16;p=7;fori=1:6imgINumber=i;imgP
2、Number=i+2;videoI=video(imgINumber);videoP=video(imgPNumber);imgI=double(videoI.cdata);imgP=double(videoP.cdata);[rowcol]=size(imgI);%ExhaustiveSearch基于块的全搜索算法[BlockCenter,motionVect,computations]=motionEstES(imgP,imgI,mbSize,p);%P帧当前重构图像imgPComp=motionComp(imgI,
3、motionVect,mbSize);%P帧当前图像和P帧当前重构图像的PSNR值ESpsnr(i+1)=imgPSNR(imgP,imgPComp,255);EScomputations(i+1)=computations;%P帧当前重构误差图像imagePDiff=imgP-imgPComp;ifi==4figure;imageI=uint8(imgI);imageP=uint8(imgP);imagePComp=uint8(imgPComp);imagePDiff=uint8(imagePDiff);subplot
4、(221);imshow(imageI);title('I帧参考图像');subplot(222);imshow(imageP);title('P帧当前图像');subplot(223);imshow(imagePComp);title('P帧当前重构图像');subplot(224);imshow(imagePDiff);title('P帧当前重构误差图像');%画运动矢量图figure;quiver(BlockCenter(2,:),BlockCenter(1,:),motionVect(2,:),motionVec
5、t(1,:),.2,'r');axis([03200240]);fori=mbSize:mbSize:col-mbSizex=[i,i];y=[0,row];line(x,y,'LineStyle','-','Marker','none');endforj=mbSize:mbSize:row-mbSizex=[0,col];y=[j,j];line(x,y,'LineStyle','-','Marker','none');endxlabel('X');ylabel('Y');endend1.文件motionEstES.m
6、%Computesmotionvectorsusingexhaustivesearchmethod(全搜索法计算运动矢量)%%Input%imgP:Theimageforwhichwewanttofindmotionvectors(当前图像)%imgI:Thereferenceimage(参考图像)%mbSize:Sizeofthemacroblock(宏块尺寸)%p:Searchparameter(readliteraturetofindwhatthismeans)(搜索参数)%%Ouput%motionVect:th
7、emotionvectorsforeachintegralmacroblockinimgP(当前图像中每一个积分宏块的运动矢量)%EScomputations:Theaveragenumberofpointssearchedforamacroblock(每个宏块搜索的平均点数)%%WrittenbyArohBarjatyafunction[BlockCenter,motionVect,EScomputations]=motionEstES(imgP,imgI,mbSize,p)%定义函数文件motionEstES.m,i
8、mgP、imgI、mbSize、p为传入参数,BlockCenter、motionVect、EScomputations为返回参数[rowcol]=size(imgI);%将参考图像的行数赋值给row,列数赋值给colblockcenter=zeros(2,row*col/mbSize^2);vectors=zero