Image manipulation

Other topics

Opening images

Matplotlib includes the image module for image manipulation

import matplotlib.image as mpimg
import matplotlib.pyplot as plt

Images are read from file (.png only) with the imread function:

img = mpimg.imread('my_image.png')

and they are rendered by the imshow function:

plt.imshow(img)

Let's plot the Stack Overflow logo:

import matplotlib.image as mpimg
import matplotlib.pyplot as plt
img = mpimg.imread('so-logo.png')
plt.imshow(img)
plt.show()

The resulting plot is Simple plot of the SO logo

Contributors

Topic Id: 4575

Example Ids: 16058

This site is not affiliated with any of the contributors.