No conversion from RGB to YUV

romeasy picture romeasy · Jun 2, 2016 · Viewed 9.7k times · Source

I fail to find an easy-to-use function in any Python library (preferrably PIL) for conversion from RGB to YUV. Since I have to convert many images, I don't want to implement it myself (would be expensive without LUTs and so on).

When I do the intuitive:

from PIL import Image
img = Image.open('test.jpeg')
img_yuv = img.convert('YUV')

I get an error:

ValueError: conversion from RGB to YUV not supported

Do you know why this is the case? Is there any efficieint implementation of that in python and maybe even PIL?

I am no computer vision expert but I thought this ocnversion is standard in most of the libraries...

Thanks,

Roman

Answer

Prasanna Parthasarathy picture Prasanna Parthasarathy · Feb 22, 2017

You can try this:

import cv2
img_yuv = cv2.cvtColor(img, cv2.COLOR_BGR2YUV)