Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 707
chenfei Avatar asked Oct 25 '16 00:10

chenfei


2 Answers

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

Original Image => Output Image

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

enter image description here

like image 185
Devendra Lattu Avatar answered Nov 18 '22 02:11

Devendra Lattu


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

like image 41
chenfei Avatar answered Nov 18 '22 00:11

chenfei