%主程序
close all;
clear
fid = fopen('E:\cat\flower_cif\flower_cif.yuv','r')
row=176*2;col=144*2;
frames=20; % total=300
for frame=1:frames
Y=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),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');
UU(1:2:row-1,1:2:col-1,frame)=U(:,:,frame);
UU(1:2:row-1,2:2:col,frame)=U(:,:,frame);
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 );
G = Y + 0.395 * (UU-128 ) - 0.581 *(VV-128);
B = Y + 2.032 *(UU-128);
for i=1:row
for j=1:col
if R(i,j,frame)<0
R(i,j,frame)=0;
end
if R(i,j,frame)>255
R(i,j,frame)=255;
end
if G(i,j,frame)<0
G(i,j,frame)=0;
end
if G(i,j,frame)>255
G(i,j,frame)=255;
end
if B(i,j,frame)<0
B(i,j,frame)=0;
end
if B(i,j,frame)>255
B(i,j,frame)=255;
end
end
end
R=R/255;G=G/255;B=B/255;
images(:,:,1)=R(:,:,frame)';
images(:,:,2)=G(:,:,frame)';
images(:,:,3)=B(:,:,frame)';
pic(:,:,:,frame)=images;
end
mbSize = 16;
p = 7;
for i = 1:6
imgINumber = i;
imgPNumber = i+1;
% imgI= pic(:,:,:,imgINumber);%前一帧的图片
% imgP= pic(:,:,:,imgPNumber);%当前帧的图片
imgI= rgb2gray(pic(:,:,:,imgINumber));%前一帧的图片
imgP= rgb2gray(pic(:,:,:,imgPNumber));%当前帧的图片
[row col] = size(imgI);
[BlockCenter, motionVect, computations] = motionEstES(imgP,imgI,mbSize,p);
% P 帧当前重构图像
imgPComp = motionComp(imgI, motionVect, mbSize);
% P 帧当前图像 和 P 帧当前重构图像的PSNR值
%ESpsnr(i+1) = imgPSNR(imgP, imgPComp, 255);
%EScomputations(i+1) = computations;
% P 帧当前重构误差图像
imagePDiff = imgP - imgPComp;
if i == 4
figure;
subplot(221);imshow(imgI);
title('I 帧参考图像');
subplot(222);imshow(imgP);
title('P 帧当前图像');
subplot(223);imshow(imgPComp);
title('P 帧当前重构图像');
subplot(224);imshow(imagePDiff);
title('P 帧当前重构误差图像');
% 画运动矢量图
figure;
quiver( BlockCenter(2,:), BlockCenter(1,:), motionVect(2,:), motionVect(1,:), .2,'r');
axis([0 320 0 240]);
for i=mbSize:mbSize:col-mbSize
x = [i,i];
y = [0,row];
line(x,y,'LineStyle','-','Marker','none');
end
for j=mbSize:mbSize:row-mbSize
x = [0,col];
y = [j,j];
line(x,y,'LineStyle','-','Marker','none');
end
xlabel('X');
ylabel('Y');
end
end
%end
评论0