scipy.misc.imshow RuntimeError('Could not execute image view')

梦想的初衷 提交于 2019-12-05 07:55:06

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

I solved my problem by:

1 adding the following to /etc/profile

SCIPY_PIL_IMAGE_VIEWER=/bin/eog
export SCIPY_PIL_IMAGE_VIEWER

2 reboot

if you do not export SCIPY_PIL_IMAGE_VIEWER,

cmd = os.environ.get('SCIPY_PIL_IMAGE_VIEWER', 'see')

will not recognize SCIPY_PIL_IMAGE_VIEWER

The following also works for me (much lighter and faster than using matplotlib):

from os import environ
environ['SCIPY_PIL_IMAGE_VIEWER'] = {your image viewer pgm} # e.g. C:/IrfanView/i_view32.exe

I can then use scipy's imshow().

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!