When you are processing images using python, you may encounter this error: module ‘scipy.misc’ has no attribute ‘imread’. In this tutorial, we will introduce you how to fix this problem.
Look at example code below:
import scipy.misc original_img = np.array(scipy.misc.imread('lake-1.jpg'), dtype=np.float64) / 255
Run this code, you will get this error.
How to fix this attribute error?
scipy.misc.imread() is removed in 1.2.0 version, we can use imageio.imread() or pillow to read image.
We can install imageio library.
pip install imageio
Then we can modify code above to:
import imageio original_img = np.array(imageio.imread('lake-1.jpg'), dtype=np.float64) / 255
Then this attribute error is fixed.
Hello, I tried to follow the code but end up getting matrixs of the array and not the image which I wanted to read.
You have got the data ndarray, and is it not what you want?
If you want to read an image to ndarray, here are some other ways:
pillow:
https://www.tutorialexample.com/python-pillow-read-image-to-numpy-array-a-step-guide-python-pillow-tutorial/
opencv:
https://www.tutorialexample.com/python-opencv-read-an-image-to-numpy-ndarray-a-beginner-guide-opencv-tutorial/