This recipe is about dealing with matrix channels. Getting access to individual channels, swapping them, and performing algebraic operations are all covered here.
Manipulating image channels
Getting ready
You need to have OpenCV 3.x installed with Python API support.
How to do it...
Perform the following steps:
- Import all necessary modules, open the image, and output its shape:
import cv2, numpy as np
image = cv2.imread('../data/Lena.png').astype(np.float32) / 255
print('Shape:', image.shape)
- Swap the red and blue channels and display the result: