scipy.misc.imshow RuntimeError('无法执行图像视图') [英] scipy.misc.imshow RuntimeError('Could not execute image view')
问题描述
我正在测试 =>
PS如果我们直接将图像绘制为 plt.imshow(img_tinted)
,那么如果呈现给它的数据不是unit8的形式,它有时会产生奇怪的结果。因此,为了防止这种情况,我们明确地将 np.uint8
转换为图像,例如 plt.imshow(np.uint8(img_tinted))
以下图片显示缺少np.uint8时的输出
I am testing scipy.misc.imshow and I got RuntimeError: Could not execute image viewer.
I am using Python3.4 and running it on CentOS 7.
import scipy.misc
img = scipy.misc.imread('Data/cat.jpg')
assert len(img.shape) == 3
img_resized = scipy.misc.imresize(img, (224, 224))
img_answer = (img_resized/255.0).astype('float32')
scipy.misc.imshow(img_answer)
And I got an error:
sh: see: command not found
Traceback (most recent call last):
File "/usr/local/pycharm/helpers/pydev/pydev_run_in_console.py", line 71, in <module>
globals = run_file(file, None, None)
File "/usr/local/pycharm/helpers/pydev/pydev_run_in_console.py", line 31, in run_file
pydev_imports.execfile(file, globals, locals) # execute the script
File "/usr/local/pycharm/helpers/pydev/_pydev_imps/_pydev_execfile.py", line 18, in execfile
exec(compile(contents+"\n", file, 'exec'), glob, loc)
File "/root/PycharmProjects/myVQA/testgood.py", line 6, in <module>
scipy.misc.imshow(img_answer)
File "/usr/lib64/python3.4/site-packages/scipy/misc/pilutil.py", line 442, in imshow
raise RuntimeError('Could not execute image viewer.')
RuntimeError: Could not execute image viewer.
It says that the see
command is not found. Where is the see
command installed on CentOS7? How can I fix the problem?
I tried to add SCIPY_PIL_IMAGE_VIEWER=/bin/eog
to /etc/profile
but it seems to be no help.
You can use matplotlib.pyplot as an alternative to using SciPy's imshow method.
import scipy.misc
img = scipy.misc.imread('Data/cat.jpg')
assert len(img.shape) == 3
img_resized = scipy.misc.imresize(img, (224, 224))
img_answer = (img_resized/255.0).astype('float32')
import matplotlib.pyplot as plt
plt.imshow(np.uint8(img_tinted))
plt.show()
=>
P.S. If we directly plot the image as plt.imshow(img_tinted)
, then it might sometimes give weird results if the data presented to it is not in the form of unit8. Hence, to prevent this we explicitly cast np.uint8
to the image such as plt.imshow(np.uint8(img_tinted))
The following images show output in the absence of np.uint8
这篇关于scipy.misc.imshow RuntimeError('无法执行图像视图')的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!