Images
Load an image as a numpy array
import matplotlib.pyplot image = matplotlib.pyplot.imread('image.png')
- Note, it requires importing a module
- The image must be in the same directory and must be a png image
Note that it is a 3 dimensional array of numbers in the range 0-1
print(image.shape) print(image.min(), image.max())
- The first two dimensions are the width and height of the image
- The last is the number of color channels
Since an image is an array, can manipulate the array and then save it as a new file
dark_image = image / 2.0 matplotlib.pyplot.imsave('dark_image.png', dark_image)