I tried making some Perlin noise but with from scipy.misc import toimage
I get an ImportError:
Traceback (most recent call last): File "C:\Perlintest.py", line 3, in <module> from scipy.misc import toimage ImportError: cannot import name 'toimage' from 'scipy.misc' (C:\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\scipy\misc\__init__.py)
scipy.misc.toimage
is removed since version 1.2, link to documentation . As the documentation suggests.
Use Pillow's Image.fromarray directly instead
It's somewhat confusing if you're a new user. So, explaining a bit. It expects you already have Pillow installed. If not first pip install numpy scipy
first and then pip install Pillow
.
Example code from the official Pillow Image.fromarray
documentation
from PIL import Image
import numpy as np
im = Image.open('image.jpg')
a = np.asarray(im)
im = Image.fromarray(a)
Otherwise, use an older version of scipy
.
For any above I recommend generating requirements.txt
or if you use conda then env.yml
for your project dependencies and future use of your project without their versioning and import errors.
you can try the below
from PIL import Image
import matplotlib.pyplot as plt
img = Image.open('name.jpg')
plt.imshow(img)
I fixed it by changing
from scipy.misc import toimage
to:
from scipy.misc.pilutil import toimage
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.