资源描述:
《matlab读取YUV视频》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、closeall;clearfid=fopen('D:Image-Sequenceakiyo_cif.yuv','r')row=176*2;col=144*2;frames=8;%total=300forframe=1:framesY=zeros(row,col,frames);U=zeros(row/2,col/2,frames);V=zeros(row/2,col/2,frames);UU=zeros(row,col,frames);VV=zeros(row,col,frames);[Y(:,:,frame)
2、,count]=fread(fid,[row,col],'uchar');[U(:,:,frame),count1]=fread(fid,[row/2,col/2],'uchar');[V(:,:,frame),count2]=fread(fid,[row/2,col/2],'uchar');%fclose(fid)%figure,imshow(Y);UU(1:2:row-1,1:2:col-1,frame)=U(:,:,frame);UU(1:2:row-1,2:2:col,frame)=U(:,:,frame);
3、UU(2:2:row,1:2:col-1,frame)=U(:,:,frame);UU(2:2:row,2:2:col,frame)=U(:,:,frame);VV(1:2:row-1,1:2:col-1,frame)=V(:,:,frame);VV(1:2:row-1,2:2:col,frame)=V(:,:,frame);VV(2:2:row,1:2:col-1,frame)=V(:,:,frame);VV(2:2:row,2:2:col,frame)=V(:,:,frame);R=Y+1.140*(VV-128
4、);G=Y+0.395*(UU-128)-0.581*(VV-128);B=Y+2.032*(UU-128);fori=1:rowforj=1:colifR(i,j,frame)<0R(i,j,frame)=0;endifR(i,j,frame)>255R(i,j,frame)=255;endifG(i,j,frame)<0G(i,j,frame)=0;endifG(i,j,frame)>255G(i,j,frame)=255;endifB(i,j,frame)<0B(i,j,frame)=0;endifB(i,j,
5、frame)>255B(i,j,frame)=255;endendendR=R/255;G=G/255;B=B/255;%X=[R',G',B'];figure,imshow(R(:,:,frame)',G(:,:,frame)',B(:,:,frame)');%M(frame)=im2frame(X,map);end%movie(M,10,30)