I am trying to open a JPG image using matplotlib in Python. Editor 'Spyder', Python3.6, WIndows 7
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
import numpy as np
# Read in the image and print some stats
image = mpimg.imread(r'C:\Users\xxx\Python Code\mountain.jpg')
print('This image is: ',type(image),
'with dimensions:', image.shape)
But I am getting the following error... It says that except '.png' no other image format is supported.
Error :-- image = mpimg.imread(r'C:\Users\xxx\Python Code\mountain.jpg')
File "C:\temp\Continuum\anaconda3\lib\site-packages\matplotlib\image.py",
line 1284, in imread
'more images' % list(handlers))
ValueError: Only know how to handle extensions: ['png']; with Pillow
installed matplotlib can handle more images.
I went through various documentations. Which says that, in order to open a '.jpg' image, 'Pillow' must be installed. If native matplotlib call fails to open a image then it automatically falls back on 'pillow'. (correct me if I am wrong)
So I installed 'Pillow'. But I am still getting the error.
Can you tell me what am I Missing ? (Strange thing is this same code is running in another computer. I have no way to verify what library is installed in that machine)
Matplotlib is a widely used data visualization library in python. This article illustrates how to display, modify and save an image using the 'matplotlib' library. We will see how to use the 'image' module as it makes working with images quite easy.
Matplotlib requires PIL(Python Imaging Library) to work with .jpg
format. To use it you need to install Pillow (which is the fork of PIL).
Installation Using PIP
pip install pillow
or
pip3 install pillow
Installation Using Conda
conda install pillow
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With