matlab中有自带的rgb转ycbcr函数,但是根据观测,其Y的值为[16 235],不符合我们的要求,所以,提供另一种规范下的转换脚本函数,其Y的值满足[0 255]
RGB转YUV
% function yuv = myrgb2yuv(image) % input params. % image: input color image with 3 channels, which value must be [0 255] % output % yuv: 3 channels(YUV444, Y plane, U plane, V plane), value [0 255], double % % % Author: KevenLee % Contact: hudalikm@163.com % Version: V1.0 function yuv = myrgb2yuv(image) image = double(image); R = image(:,:,1); G = image(:,:,2); B = image(:,:,3); yuv(:,:,1) = 0.299.*R + 0.587.*G + 0.114.*B; yuv(:,:,2) = - 0.1687.*R - 0.3313.*G + 0.5.*B + 128; yuv(:,:,3) = 0.5.*R - 0.4187.*G - 0.0813.*B + 128; end
YUV转RGB
% fun