ttributeError: module 'scipy.misc' has no attribute 'imresize'
时间: 2023-11-09 11:09:26 浏览: 60
这个错误提示表明在使用 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 表示希望将原始图像缩放后的大小。
相关问题
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.
AttributeError: scipy.misc is deprecated and has no attribute imresize.
引用中提到了一个错误信息:AttributeError: module 'scipy.misc' has no attribute 'imresize',这意味着在scipy.misc模块中没有imresize属性。引用和进一步解释了这个问题:imresize函数在SciPy 1.0.0版本中已经被弃用,并且将在1.3.0版本中移除。取而代之的是使用Pillow库中的Image对象的resize方法来实现相同的功能。你可以使用以下代码来替代imresize函数的使用:
```python
import numpy as np
from PIL import Image
my_image = np.array(Image.fromarray(image).resize((64, 64)))
```
这样就可以避免使用已弃用的imresize函数并解决AttributeError错误。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* *2* [AttributeError: module 'scipy.misc' has no attribute 'imresize'等问题解决](https://blog.csdn.net/lly1122334/article/details/102383111)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"]
- *3* [scipy.misc is deprecated and has no attribute imresize](https://blog.csdn.net/weixin_45766582/article/details/131573556)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]