今天使用scikit-image读取图片后,发现图片是一个三维数组,按理解图片不该是一个二维数组么?为什么是一个三维数组呢?
是三维没错,长,宽,通道
通道:R(红)G(绿)B(蓝)
或A(Alpha)R(红)G(绿)B(蓝)
Alpha:透明度
彩色图像有RGB三个通道,表示图像颜色
是三维的,正常来说(H,W,C)
如果考虑batch-size的话,会到四维——(N,H,W,C)
例如:比如你使用skimage.io.imread函数,关于返回的是几维数据,你可以根据函数说明来,首先给出函数定义,源码,https://github.com/scikit-image/scikit-image/blob/master/skimage/io/_io.py#L14
函数定义:
def imread(fname, as_gray=False, plugin=None, flatten=None,
**plugin_args):
"""Load an image from file.
Parameters
----------
fname : string
Image file name, e.g. ``test.jpg`` or URL.
as_gray : bool, optional
If True, convert color images to gray-scale (64-bit floats).
Images that are already in gray-scale format are not converted.
plugin : str, optional
Name of plugin to use. By default, the different plugins are
tried (starting with imageio) until a suitable
candidate is found. If not given and fname is a tiff file, the
tifffile plugin will be used.
Other Parameters
----------------
plugin_args : keywords
Passed to the given plugin.
flatten : bool
Backward compatible keyword, superseded by `as_gray`.
Returns
-------
img_array : ndarray
The different color bands/channels are stored in the
third dimension, such that a gray-image is MxN, an
RGB-image MxNx3 and an RGBA-image MxNx4.
这里关于返回值明确写了:
img_array : ndarray
The different color bands/channels are stored in the
third dimension, such that a gray-image is MxN, an
RGB-image MxNx3 and an RGBA-image MxNx4.
所以说,还是需要结合具体的函数来,而不是想当然。