我正在使用 Debian Linux 和 python 2.7。
我正在读取图像并尝试对其进行处理,但我看到了以下错误。有人可以告诉我我做错了什么吗?
import Image
import scipy
from scipy import ndimage
import matplotlib.pyplot as plt
import numpy as np
from scipy import misc
import scipy.misc
img = scipy.misc.imread("/home/subhradeep/Desktop/test.jpg")
array=np.asarray(img)
plt.figure(figsize=(10, 3.6))
plt.subplot(131)
plt.imshow(array, cmap=plt.cm.gray)
plt.subplot(132)
plt.imshow(array, cmap=plt.cm.gray, vmin=10, vmax=100)
plt.axis('off')
plt.subplot(133)
plt.imshow(array, cmap=plt.cm.gray)
plt.contour(array, [160, 211])
plt.axis('off')
plt.subplots_adjust(wspace=0, hspace=0., top=0.99, bottom=0.01, left=0.05,right=0.99)
plt.show()
我收到以下错误消息
Traceback (most recent call last):
File "1saveimg.py", line 22, in <module>
plt.contour(array, [160, 211])
File "/usr/lib/pymodules/python2.7/matplotlib/pyplot.py", line 2632, in contour
ret = ax.contour(*args, **kwargs)
File "/usr/lib/pymodules/python2.7/matplotlib/axes.py", line 7976, in contour
return mcontour.QuadContourSet(self, *args, **kwargs)
File "/usr/lib/pymodules/python2.7/matplotlib/contour.py", line 1414, in __init__
ContourSet.__init__(self, ax, *args, **kwargs)
File "/usr/lib/pymodules/python2.7/matplotlib/contour.py", line 860, in __init__
self._process_args(*args, **kwargs)
File "/usr/lib/pymodules/python2.7/matplotlib/contour.py", line 1427, in _process_args
x, y, z = self._contour_args(args, kwargs)
File "/usr/lib/pymodules/python2.7/matplotlib/contour.py", line 1488, in _contour_args
x, y = self._initialize_x_y(z)
File "/usr/lib/pymodules/python2.7/matplotlib/contour.py", line 1573, in _initialize_x_y
raise TypeError("Input must be a 2D array.")
TypeError: Input must be a 2D array.
我也尝试过Image.open()
,但这也引发了同样的错误。