scipy.misc.imread()函数用于从文件中读取图像作为数组。
scipy.misc.imread(name,
flatten=False,
mode=None
)
参数:
-
name
:str或file对象。要读取的文件名或文件对象。 -
flatten
:bool,可选。如果为True,则将颜色层展平为单个灰度图层。 -
mode
:str,可选。将图像转换为例如的模式’RGB’。
返回:
-
imread
:ndarray。通过读取图像获得的阵列。
注意:
"""
Notes
-----
`imread` uses the Python Imaging Library (PIL) to read an image.
The following notes are from the PIL documentation.
`mode` can be one of the following strings:
* 'L' (8-bit pixels, black and white)
* 'P' (8-bit pixels, mapped to any other mode using a color palette)
* 'RGB' (3x8-bit pixels, true color)
* 'RGBA' (4x8-bit pixels, true color with transparency mask)
* 'CMYK' (4x8-bit pixels, color separation)
* 'YCbCr' (3x8-bit pixels, color video format)
* 'I' (32-bit signed integer pixels)
* 'F' (32-bit floating point pixels)
PIL also provides limited support for a few special modes, including
'LA' ('L' with alpha), 'RGBX' (true color with padding) and 'RGBa'
(true color with premultiplied alpha).
When translating a color image to black and white (mode 'L', 'I' or
'F'), the library uses the ITU-R 601-2 luma transform::
L = R * 299/1000 + G * 587/1000 + B * 114/1000
When `flatten` is True, the image is converted using mode 'F'.
When `mode` is not None and `flatten` is True, the image is first
converted according to `mode`, and the result is then flattened using
mode 'F'.
"""
以下是翻译:
imread
使用Python Imaging Library(PIL)读取图像。以下注释来自PIL文档。
mode
可以是以下字符串之一:
- ‘L’(8位像素,黑白)
- ‘P’(8位像素,使用调色板映射到任何其他模式)
- ‘RGB’(3x8位像素,真彩色)
- ‘RGBA’(4x8位像素,带透明蒙版的真彩色)
- ‘CMYK’(4x8位像素,分色)
- ‘YCbCr’(3x8位像素,彩色视频格式)
- ‘I’(32位有符号整数像素)
- ‘F’(32位浮点像素)
PIL还为一些特殊模式提供有限的支持,包括’LA’(带有alpha的’L’),‘RGBX’(带填充的真彩色)和’RGBa’(带有预乘alpha的真彩色)。
将彩色图像转换为黑白(模式“L”,“I”或“F”)时,库使用ITU-R 601-2亮度转换:
L=R∗299/1000+G∗587/1000+B∗114/1000
当flatten
为True时,使用mode
“F”转换图像。当mode
不是None并且flatten
为True时,首先根据mode
转换图像,然后使用mode
’F’flatten
结果。