module 'scipy.ndimage' has no attribute 'imread'
时间: 2023-05-21 14:04:06 浏览: 91
这个问题可能是因为您使用的是较新版本的 Scipy 库,而该库中已经不再支持 imread 函数。您可以尝试使用 Pillow 库中的 Image 模块来读取图像文件。以下是一个示例代码:
```python
from PIL import Image
img = Image.open('image.jpg')
```
请注意,您需要先使用 pip 安装 Pillow 库,命令如下:
```
pip install Pillow
```
相关问题
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.
module 'scipy.ndimage' has no attribute 'imread'怎么处理
这个错误发生是因为scipy.ndimage模块中没有imread这个属性。如果想要读取图像,可以使用其他的库,比如Pillow或OpenCV。以下是使用Pillow的示例代码:
```python
from PIL import Image
# 读取图像
img = Image.open("image.jpg")
# 显示图像
img.show()
# 转换为数组
img_array = np.array(img)
```
如果想要使用OpenCV,可以使用以下代码:
```python
import cv2
# 读取图像
img = cv2.imread("image.jpg")
# 显示图像
cv2.imshow("image", img)
cv2.waitKey(0)
# 转换为数组
img_array = np.array(img)
```