Visualizing the true-color palette

By performing the following steps, you will be able to visualize the true-color palette of a color image:

  1. Let's have a look at a particular image:
In [1]: import cv2...     import numpy as np...     lena = cv2.imread('data/lena.jpg', cv2.IMREAD_COLOR)
  1. By now, we know how to start Matplotlib in our sleep:
In [2]: import matplotlib.pyplot as plt...     %matplotlib inline...     plt.style.use('ggplot')
  1. However, this time, we want to disable the grid lines that the ggplot option typically displays over images:
In [3]: plt.rc('axes', **{'grid': False})
  1. Then, we can visualize Lena with the following command (don't forget to switch the BGR ordering of the color channels to RGB):
In [4]: plt.imshow(cv2.cvtColor(lena, cv2.COLOR_BGR2RGB)) ...

Get Machine Learning for OpenCV 4 - Second Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.