显示Imag时出现Python错误

2024-04-20 15:48:22 发布

您现在位置:Python中文网/ 问答频道 /正文

在这张照片上

enter image description here

我试图申请:

from PIL import Image
img0 = PIL.Image.open('Entertainment.jpg')
img0 = np.float32(img0)
showarray(img0/255.0)

我得到一个错误:

^{pr2}$

我不明白为什么。在

这里什么是不可赎回的?
我怎样才能显示图像?在


Tags: from图像imageimportpil错误npopen
2条回答

Image是您导入的模块

from PIL import Image

你不能这么说

^{pr2}$

有一个show方法可能很有用

img0 = PIL.Image.open('Entertainment.jpg')
img0.show() 

问题可能源于您如何导入display()函数。如果您的进口行是:

import IPython.display as display

然后需要调用display.display()来显示图像。例如:

^{pr2}$

如果将函数作为

import IPython.display as display
my_image = Image.open('something.jpg')
display(my_image) # INCORRECT
# TypeError: 'module' object is not callable

然后您将在您的原始帖子中看到错误消息,因为display是指一个模块,而不是一个函数。在

或者,如果以以下方式导入display()函数,则代码将正常工作:

from IPython.display import display
my_image = Image.open('something.jpg')
display(my_image)

相关问题 更多 >