8.1 Image Basics
Consider the following example that uses the image four-circles.jpg .
import matplotlib.pyplot as plt = plt.imread('./four-circles.jpg') # Load the image img # Display the image plt.imshow(img) 'off') # Don't show the axes plt.axis( plt.show() print(img.shape) # What type of variabe is 'img'
# (1000, 1000, 3)
We can see how
matplotlib stores image information by looking at the details of
img. The image is stored as a \(1000 \times 1000 \times 3\), np array! The image is made up of \(3\) stacked
numpy \(1000 \times 1000\) arrays.
Each of these arrays carry information about the RGB (red, green, blue) components (‘channels’). We can check this by just visualizing the ‘layers’ or ‘channels’ separately.
Note that other packages (e.g.
skimage) might store the same information in a different format (e.g. \(3\times 1000 \times 1000\)).