In this section, we will show more advanced graphical features offered by Matplotlib that are related to images and maps. We will also take a look at a few other graphical libraries.
A colored N x M image can be represented as an N x M x 3 NumPy array corresponding to three N x M matrices for the red, green, and blue channels. Image processing algorithms can then be implemented efficiently with NumPy and SciPy and visualized with Matplotlib. In addition, the PIL package (Python Imaging Library) implements basic image processing routines for pictures.
Matplotlib's imread
function opens a PNG image from the hard drive and returns an N x M x 3 (or N x M x 4 if there is an alpha transparency channel) NumPy array. It can also read other formats if PIL is installed. PIL also offers the open
function for reading images in any format (BMP, GIF, JPEG, TIFF, and so on).
In the following example, we download a PNG image from a remote URL and...