Skip to content

Instantly share code, notes, and snippets.

@chenhu66
chenhu66 / rgb2yuv_yuv2rgb.py
Created January 4, 2020 09:47 — forked from Quasimondo/rgb2yuv_yuv2rgb.py
RGB to YUV and YUV to RGB conversion for Numpy
import numpy as np
#input is a RGB numpy array with shape (height,width,3), can be uint,int, float or double, values expected in the range 0..255
#output is a double YUV numpy array with shape (height,width,3), values in the range 0..255
def RGB2YUV( rgb ):
m = np.array([[ 0.29900, -0.16874, 0.50000],
[0.58700, -0.33126, -0.41869],
[ 0.11400, 0.50000, -0.08131]])