首页->【图像处理算法与实现】

12 1

function [y,u,v] = readyuv(imgpath)

%READYUV 此处显示有关此函数的摘要
% 此处显示详细说明

%yuv422 格式

hor = 512;
ver = 132;
width=hor*2;
picture=double(zeros(ver,width));

fid = fopen(imgpath, 'r' );
if fid == -1
  error('Cannot open file.');
end

for i=1:ver
 picture(i,:) = fread(fid, hor*2, 'uint8');
end

y =uint16(zeros(ver, hor));
u = uint8(zeros(ver, hor));
v = uint8(zeros(ver, hor));

for i = 1:ver
    for j = 1:4:hor*2
        y(i, (j + 1)/2) = picture(i, j);
        u(i, (j + 1)/2) = picture(i, j + 1);
        u(i, (j + 3)/2) = picture(i, j + 1);
        y(i, (j + 3)/2) = picture(i, j + 2);
        v(i, (j + 1)/2) = picture(i, j + 3);
        v(i, (j + 3)/2) = picture(i, j + 3);
    end
end
fclose(fid);
end

楼主可见

  1. shwnyoo 1#

    每个色差信道的抽样率是亮度信道的一半,所以水平方向的色度抽样率只是

    4:4:4的一半。对非压缩的8比特量化的图像来说,每个由两个水平方向相邻的像素组成的宏像素需要占用4字节内存。

    下面的四个像素为:

    [Y0 U0 V0] [Y1 U1 V1] [Y2 U2 V2] [Y3 U3 V3]

    存放的码流为:

    Y0 U0 Y1 V1 Y2 U2 Y3 V3 

    映射出像素点为:

    [Y0 U0 V1] [Y1 U0 V1] [Y2 U2 V3] [Y3 U2 V3]