(1)在YUV颜色空间中,“Y”表示灰度,可以体现人眼对亮度的敏感程度,如果没有U和V信息,只有Y信息,图像仍然可以显示出来,只不过是灰色的;“U”和“V”表示色度,作用是描述影像色彩和饱和度,用于指定像素的颜色。“U”和“V”一起描述了色彩的饱和度以及色调。
(2)因为人眼对亮度比色度更敏感,因此色度通道(“U”和“V”)采样率可以低于亮度通道,而不会显著降低感知质量。主流的采用方式有三种:YUV444,YUV422,YUV420。
YUV444:
- 每个Y分量都对应一组UV分量
- 采样比例为4:4:4
- 1个像素点完整保留一组YUV值
- 无色度信息损失
- 数据量最大
- 质量最好
YUV422:
- 两个Y分量共用一组UV分量
- 采样比例为4:2:2
- 在水平方向上2个像素点共用一组UV值
- 轻微的色度信息损失
- 数据量是YUV444的2/3
- 中等质量
YUV420:
- 四个Y分量共用一组UV分量
- 采样比例为4:2:0
- 在水平和垂直方向上4个像素点共用一组UV值
- 色度信息损失较大
- 数据量是YUV444的1/2
- 质量较低但仍可接受
实际应用:
- YUV444:专业视频制作、高端影像处理
- YUV422:专业摄像机、高质量视频
- YUV420:视频压缩、消费级视频设备、网络视频
(3)matlab实现
% 1. 读取图像
rgb_image = imread('1_1920x1080.bmp'); % 或其他图像名称
% 获取屏幕分辨率
screen_size = get(0, 'ScreenSize');
screen_width = screen_size(3);
screen_height = screen_size(4);
% 计算合适的显示尺寸
max_single_width = (screen_width - 200) / 4;
scale = max_single_width / size(rgb_image, 2);
display_width = round(size(rgb_image, 2) * scale);
display_height = round(size(rgb_image, 1) * scale);
% 2. 将RGB图像转换为YUV444图像
yuv444_image = zeros(size(rgb_image));
R = double(rgb_image(:,:,1));
G = double(rgb_image(:,:,2));
B = double(rgb_image(:,:,3));
% RGB to YUV转换
Y = 0.299*R + 0.587*G + 0.114*B;
U = 0.5*B - 0.169*R - 0.331*G + 128;
V = 0.5*R - 0.419*G - 0.081*B + 128;
yuv444_image(:,:,1) = Y;
yuv444_image(:,:,2) = U;
yuv444_image(:,:,3) = V;
% 3. 创建YUV422格式图像
% YUV422格式:水平方向上每两个Y共用一组UV
[height, width, ~] = size(rgb_image);
yuv422_image = zeros(height, width, 3);
yuv422_image(:,:,1) = Y; % Y分量保持不变
% 对U和V进行水平方向2:1降采样
for i = 1:height
for j = 1:2:width
if j+1 <= width
% 每两个像素取平均值
yuv422_image(i,j:j+1,2) = mean(U(i,j:j+1)); % U分量
yuv422_image(i,j:j+1,3) = mean(V(i,j:j+1)); % V分量
else
% 处理最后一个像素(如果宽度为奇数)
yuv422_image(i,j,2) = U(i,j);
yuv422_image(i,j,3) = V(i,j);
end
end
end
% 4. 将YUV422图像转换回RGB
Y = yuv422_image(:,:,1);
U = yuv422_image(:,:,2);
V = yuv422_image(:,:,3);
% YUV to RGB转换
R2 = Y + 1.402*(V-128);
G2 = Y - 0.344*(U-128) - 0.714*(V-128);
B2 = Y + 1.772*(U-128);
% 确保RGB值在正确范围内
rgb_image_422 = zeros(size(rgb_image), 'uint8');
rgb_image_422(:,:,1) = uint8(min(max(R2, 0), 255));
rgb_image_422(:,:,2) = uint8(min(max(G2, 0), 255));
rgb_image_422(:,:,3) = uint8(min(max(B2, 0), 255));
% 5. 显示图像
% 计算窗口位置
window_spacing = 50;
x_pos1 = round((screen_width - 4*display_width - 3*window_spacing)/2);
x_pos2 = x_pos1 + display_width + window_spacing;
x_pos3 = x_pos2 + display_width + window_spacing;
x_pos4 = x_pos3 + display_width + window_spacing;
y_pos = round((screen_height - display_height)/2);
% 显示原始RGB图像
figure('Name', 'Original RGB', 'NumberTitle', 'off');
imshow(imresize(rgb_image, [display_height display_width]));
set(gcf, 'Position', [x_pos1 y_pos display_width display_height]);
% 显示YUV444图像
figure('Name', 'YUV444', 'NumberTitle', 'off');
imshow(uint8(imresize(yuv444_image, [display_height display_width])));
set(gcf, 'Position', [x_pos2 y_pos display_width display_height]);
% 显示YUV422图像
figure('Name', 'YUV422', 'NumberTitle', 'off');
imshow(uint8(imresize(yuv422_image, [display_height display_width])));
set(gcf, 'Position', [x_pos3 y_pos display_width display_height]);
% 显示YUV422转换回的RGB图像
figure('Name', 'RGB from YUV422', 'NumberTitle', 'off');
imshow(imresize(rgb_image_422, [display_height display_width]));
set(gcf, 'Position', [x_pos4 y_pos display_width display_height]);