from PIL import Image
img = Image.open("test.jpg")
print img.size
print img.getpixel((0,0))
输出结果是
(533, 800)
(217, 229, 225)
img = cv2.imread(""test.jpg"")
print img.shape
print img[0][0]
输出结果是
(800, 533, 3)
[225 229 217]
img = cv2.imread(""test.jpg"")[..., ::-1]
print img.shape
print img[0][0]
输出结果是
(800, 533, 3)
[217 229 225]
和用PIL 读取完的一致
首先我们先来看一下这个函数的定义
def imread(filename, flags=None)
- Windows bitmaps - \*.bmp, \*.dib (always supported)
- JPEG files - \*.jpeg, \*.jpg, \*.jpe (see the *Note* section)
- JPEG 2000 files - \*.jp2 (see the *Note* section)
- Portable Network Graphics - \*.png (see the *Note* section)
- WebP - \*.webp (see the *Note* section)
- Portable image format - \*.pbm, \*.pgm, \*.ppm \*.pxm, \*.pnm (always supported)
- Sun rasters - \*.sr, \*.ras (always supported)
- TIFF files - \*.tiff, \*.tif (see the *Note* section)
- OpenEXR Image files - \*.exr (see the *Note* section)
- Radiance HDR - \*.hdr, \*.pic (always supported)
- Raster and Vector geospatial data supported by GDAL (see the *Note* section)
参数 | Value |
---|---|
IMREAD_UNCHANGED | If set, return the loaded image as is (with alpha channel, otherwise it gets cropped). |
IMREAD_GRAYSCALE | If set, always convert image to the single channel grayscale image. |
IMREAD_COLOR | If set, always convert image to the 3 channel BGR color image. |
IMREAD_ANYDEPTH | If set, return 16-bit/32-bit image when the input has the corresponding depth, otherwise convert it to 8-bit. |
IMREAD_ANYCOLOR | If set, the image is read in any possible color format. |
IMREAD_LOAD_GDAL | If set, use the gdal driver for loading the image. |
参数 | Value |
---|---|
flag=-1时 | 8位深度,原通道 |
flag=0 | 8位深度,1通道 |
flag=1 | 8位深度 ,3通道 |
flag=2 | 原深度,1通道 |
flag=3 | 原深度,3通道 |
flag=4 | 8位深度 ,3通道 |