Displaying images with other plots in the figure
This recipe will show how we can make simple yet effective usage of Python matplotlib library to process image channels and display the per-channel histogram of an external image.
Getting ready
We have provided some sample images, but the code is ready to load any image file, provided it is supported by matplotlib's imread
function.
In this recipe, you will learn how to combine different matplotlib plots to achieve functionality of a simple image viewer that displays an image histogram for red, green, and blue channels.
How to do it...
To show how to build an image histogram viewer, we are going to implement a simple class named ImageViewer
, and that class will contain helper methods to:
Load image.
Separate RGB channels from image matrix.
Configure figure and axes (subplots).
Plot channel histograms.
Plot the image.
The following code shows how to build an image histogram viewer:
import matplotlib.pyplot as plt import matplotlib.image as mplimage import...