Y = 0.257 * R + 0.504 * G + 0.098 * B + 16 U = -0.148 * R - 0.291 * G + 0.439 * B + 128 V = 0.439 * R - 0.368 * G - 0.071 * B + 128 根据RGB到YUV的转换公式,推导出YUV到RGB的转换公式。
时间: 2023-09-04 08:11:44 浏览: 172
根据RGB到YUV的转换公式:
Y = 0.257 * R + 0.504 * G + 0.098 * B + 16
U = -0.148 * R - 0.291 * G + 0.439 * B + 128
V = 0.439 * R - 0.368 * G - 0.071 * B + 128
将U和V带入Y的公式中,得到:
Y = 0.257 * R + 0.504 * G + 0.098 * B + 16
U - 128 = -0.148 * R - 0.291 * G + 0.439 * B
V - 128 = 0.439 * R - 0.368 * G - 0.071 * B
移项并消元,得到:
R = 1.164*(Y-16) + 1.596*(V-128)
G = 1.164*(Y-16) - 0.813*(V-128) - 0.391*(U-128)
B = 1.164*(Y-16) + 2.018*(U-128)
因此,YUV到RGB的转换公式为:
R = 1.164*(Y-16) + 1.596*(V-128)
G = 1.164*(Y-16) - 0.813*(V-128) - 0.391*(U-128)
B = 1.164*(Y-16) + 2.018*(U-128)
相关问题
function [ yuvimg ] = BUPT_format_converter() % Title: This function convert an image from colour to grey scale % Image created by Yun Bo % Convert matrix T = [0.257 0.504 0.098; -0.148 -0.291 0.439; 0.439 -0.368 -0.071]; %offset matrix offset = [16;128;128]; % read the rgb image and seperate R G B [I,w,h,level]=ppmread('./test_images/Lena512C_ASCII2014.ppm'); I=double(I); R=I(:,:,1); G=I(:,:,2); B=I(:,:,3); %map between RGB and YUV Y = T(1,1) .* R + T(1,2) .* G + T(1,3) .* B + offset(1); U = T(2,1) .* R + T(2,2) .* G + T(2,3) .* B + offset(2); V = T(3,1) .* R + T(3,2) .* G + T(3,3) .* B + offset(3); %get YVU output yuvimg = cat(3,Y,U,V); imwrite(yuvimg(:,:,1),'Lena_Y.jpg'); figure,imshow(yuvimg(:,:,1)); imwrite(yuvimg,'Lena_YUV.jpg'); figure,imshow(yuvimg); %transform YVU to RGB again Y=double(Y); U=double(U); V=double(V); RR = 1.164*(Y-16)+1.596*(V-128); GG = 1.164*(Y-16)-0.813*(V-128)-0.391*(U-128); BB = 1.164*(Y-16)+2.018*(U-128); RR = uint8(round(RR)); GG = uint8(round(GG)); BB = uint8(round(BB)); rgbimg = cat(3,RR,GG,BB); imwrite(rgbimg,'Lena_RGB.jpg'); figure,imshow(rgbimg); end这个代码无法显示yuvimg与yuvimg(:,:,1)),请帮我修改一下
可以尝试在显示yuvimg时指定显示的范围,以及设置图像标题,如下所示:
```matlab
imshow(yuvimg(:,:,1), [0 255]);
title('Y Component of YUV Image');
figure, imshow(yuvimg);
title('YUV Image');
```
同样,在显示yuvimg(:,:,1)时也需要指定显示的范围和设置标题:
```matlab
imshow(yuvimg(:,:,1), [0 255]);
title('Y Component of YUV Image');
```
在imshow函数中,[0 255]表示显示的范围为0到255。
y = 0.257 * r + 0.504 * g + 0.098 * b + 16 u = -0.148 * r - 0.291 * g + 0.439 * b + 128根据RGB到YUV的转换公式,推导出YUV到RGB的转换公式。 V = 0.439 * R - 0.368 * G - 0.071 * B + 128
根据YUV到RGB的转换公式:
R = 1.164*(Y-16) + 1.596*(V-128)
G = 1.164*(Y-16) - 0.813*(V-128) - 0.392*(U-128)
B = 1.164*(Y-16) + 2.017*(U-128)
其中,Y、U、V分别表示YUV颜色空间中的亮度、色度分量。
将YUV到RGB的转换公式代入原公式中得到:
R = Y + 1.13983*(V-128)
G = Y - 0.39465*(U-128) - 0.58060*(V-128)
B = Y + 2.03211*(U-128)
因此,YUV到RGB的转换公式为:
R = Y + 1.13983*(V-128)
G = Y - 0.39465*(U-128) - 0.58060*(V-128)
B = Y + 2.03211*(U-128)
阅读全文