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