Splitting image channels

You can convert to YUV by using the following flag:

yuv_img = cv2.cvtColor(img, cv2.COLOR_BGR2YUV)

The image will look something like the following one:

This may look like a deteriorated version of the original image, but it's not. Let's separate out the three channels:

# Alternative 1y,u,v = cv2.split(yuv_img)cv2.imshow('Y channel', y)cv2.imshow('U channel', u)cv2.imshow('V channel', v)cv2.waitKey()
# Alternative 2 (Faster)cv2.imshow('Y channel', yuv_img[:, :, 0])cv2.imshow('U channel', yuv_img[:, :, 1])cv2.imshow('V channel', yuv_img[:, :, 2])cv2.waitKey()

Since yuv_img is a NumPy (which provides dimensional selection ...

Get OpenCV 3.x with Python By Example - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.