Visualizing the true-color palette

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)

By now, we know how to start matplotlib in our sleep:

In [2]: import matplotlib.pyplot as plt...     %matplotlib inline...     plt.style.use('ggplot')

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})

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))

This will produce the following output:

A picture of Lena (http://sipi.usc.edu/database/database.php?volume=misc&image=12). ...

Get Machine Learning for OpenCV 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.