把YUV420P的数据,转成RGB格式的数据用以显示
clear all;
close all;
w = 640;
h = 512;
[filename,pathname]=uigetfile({'*.yuv'},'选择数据');
fid = fopen([pathname,filename]);
data_org=fread(fid,'uint8');
fclose(fid);
s=reshape(data_org,[w h*1.5]);
Y = s(:,1:h);
UV = s(:,h+1:1.5*h);
for i = 1 : 2 :(h/2) - 1
U(:,i) = UV(1:w/2,i);
U(:,i+1) = UV(w/2+1:w,i);
V(:,i) = UV(1:w/2,i+1);
V(:,i+1) = UV(w/2+1,i+1);
end
im_y = Y';
im_cb = imresize(U', [h, w], 'nearest');
im_cr = imresize(V', [h, w], 'nearest');
im_ycbcr(:,:,1) = im_y;
im_ycbcr(:,:,2) = im_cb;
im_ycbcr(:,:,3) = im_cr;
im_rgb = ycbcr2rgb(uint8(im_ycbcr));
imshow(im_rgb,[]);