module 'scipy.misc' has no attribute 'imresize'
时间: 2023-11-14 10:07:55 浏览: 21
这个错误是因为在新版本的scipy中,imresize方法已经被弃用。如果你想使用imresize方法,你需要安装低版本的scipy,例如1.2.1版本,并且需要对应的Pillow版本为6.0.0。另外,你也可以使用其他的方法来进行图片的resize,例如利用Pillow库中的Image.fromarray()和resize()方法。
相关问题
module scipy.misc has no attribute imresize
The `imresize` function in the `scipy.misc` module is deprecated and no longer available in recent versions. It has been removed because it was not properly maintaining the aspect ratio of the image when resizing.
Instead, you can use the `resize` function from the `scipy.ndimage` module to resize images. Here's an example of how you can use it:
```python
from scipy import ndimage
import matplotlib.pyplot as plt
# Load the image
image = plt.imread('image.jpg')
# Resize the image to a specific size
resized_image = ndimage.zoom(image, (0.5, 0.5, 1))
# Display the original and resized images
plt.subplot(1, 2, 1)
plt.imshow(image)
plt.title('Original Image')
plt.subplot(1, 2, 2)
plt.imshow(resized_image)
plt.title('Resized Image')
plt.show()
```
This example resizes the image by a factor of 0.5 in both dimensions. You can adjust the zoom factors to achieve the desired size.
ttributeError: module 'scipy.misc' has no attribute 'imresize'
这个错误提示表明在使用 scipy.misc 模块中的 imresize 函数时出现了问题。具体原因可能是你的 Scipy 版本过高,而 imresize 函数在新版本中已经被弃用。建议改用 skimage.transform 模块中的 resize 函数来代替。
改用 skimage.transform 模块中的 resize 函数的示例如下:
```
from skimage.transform import resize
image_resized = resize(image, (new_height, new_width))
```
其中,image 表示原始图像,new_height 和 new_width 表示希望将原始图像缩放后的大小。