rdv*_*rdv 6 python grayscale scikit-image imread
我正在尝试将图像加载为灰度,如下所示:
from skimage import data
from skimage.viewer import ImageViewer
img = data.imread('my_image.png', as_gray=True)
Run Code Online (Sandbox Code Playgroud)
但是,如果我使用img.shape它检查它的形状,结果证明它是一个三维的,而不是二维的数组.我究竟做错了什么?
从scikit-image文档中,签名data.imread如下:
Run Code Online (Sandbox Code Playgroud)skimage.data.imread(fname, as_grey=False, plugin=None, flatten=None, **plugin_args)
您的代码无法正常运行,因为关键字参数as_grey拼写错误(您放置as_gray).
样品运行
In [4]: from skimage import data
In [5]: img_3d = data.imread('my_image.png', as_grey=False)
In [6]: img_3d.dtype
Out[6]: dtype('uint8')
In [7]: img_3d.shape
Out[7]: (256L, 640L, 3L)
In [8]: img_2d = data.imread('my_image.png', as_grey=True)
In [9]: img_2d.dtype
Out[9]: dtype('float64')
In [10]: img_2d.shape
Out[10]: (256L, 640L)
Run Code Online (Sandbox Code Playgroud)