Description
The image tutorial on matplotlib.org uses this sample image:
https://matplotlib.org/_images/stinkbug.png
and notes that it is a "24-bit RGB PNG image (8 bits for each of R, G, B)". However, further inspection reveals that it is not a 24-bit RGB, but rather an 8-bit grayscale image.
$ curl -s 'https://matplotlib.org/_images/stinkbug.png' | file -
/dev/stdin: PNG image data, 500 x 375, 8-bit grayscale, non-interlaced
However, the source image in the github repository is an RGB image:
$ curl -s 'https://raw.githubusercontent.com/matplotlib/matplotlib/master/doc/_static/stinkbug.png' | file -
/dev/stdin: PNG image data, 500 x 375, 8-bit/color RGB, non-interlaced
I noticed this because when I tried to follow the tutorial on my own machine, I kept on getting this error in line 7:
In [7]: lum_img = img[:,:,0]
IndexError: too many indices for array
This is because imread
stores a grayscale image as an ndarray with only two dimensions, not three, as documented here:
For grayscale images, the return array is MxN. For RGB images, the return value is MxNx3. For RGBA images the return value is MxNx4.
https://matplotlib.org/api/_as_gen/matplotlib.pyplot.imread.html
So img.shape
ends up as (375, 500)
when it should be (375, 500, 3)
.
Let me know if I should file this here instead: