python - scipy.misc.imshow 运行时错误 ('Could not execute image view' )

标签 python image scipy centos7 imshow

我正在测试 scipy.misc.imshow我得到了RuntimeError: Could not execute image viewer

我正在使用 Python3.4 并在 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)

我得到一个错误:

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.

它表示未找到 see 命令。 CentOS7 上安装的see 命令在哪里?我该如何解决这个问题?

我尝试将 SCIPY_PIL_IMAGE_VIEWER=/bin/eog 添加到 /etc/profile 但这似乎没有帮助。

最佳答案

您可以使用 matplotlib.pyplot作为使用 SciPy's imshow 的替代方法方法。

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()

Original Image => Output Image

附言如果我们直接将图像绘制为 plt.imshow(img_tinted),那么如果提供给它的数据不是 unit8 的形式,它有时可能会给出奇怪的结果。因此,为了防止这种情况,我们明确地将 np.uint8 转换为图像,例如 plt.imshow(np.uint8(img_tinted))

下图显示了没有 np.uint8 时的输出

enter image description here

关于python - scipy.misc.imshow 运行时错误 ('Could not execute image view' ),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40229630/

相关文章:

python - 如何用Python/Pandas减去2列未对齐的数据?

python - 资源警告 : unclosed file <_io. BufferedReader 名称=4>

ios - iOS 的多次启动图像

python - pandas - 数据框列值的线性回归

python - 使用 Out of Core 进行 Scikit Learn 多标签分类

python - 使用来自另一个 DataFrame 的组对一个 DataFrame 进行 T 检验

python - 一个压缩 list.py 的程序

python - 我的数据框有很多(192)列。如何同时选择两列?

java - 有损压缩中的隐写术 (JAVA)

android - QCAR中使用的图像检测技术