Python:来自图像的转换矩阵是3D而不是2D

时间:2015-09-18 00:17:31

标签: python image numpy matrix python-imaging-library

我将图像转换为numpy数组并返回3D数组而不是2D(宽度和高度)。

我的代码是:

import PIL
from PIL import Image
import numpy as np

samp_jpg = "imgs_subset/w_1.jpg"
samp_img = Image.open(samp_jpg)
print samp_img.size
(3072, 2048)
I = np.asarray(samp_img)
I.shape
(2048, 3072, 3)

3D矩阵看起来像:

array([[[ 58,  95, 114],
        [ 54,  91, 110],
        [ 52,  89, 108],
        ..., 
        [ 48,  84, 106],
        [ 50,  85, 105],
        [ 51,  86, 106]],

       [[ 63, 100, 119],
        [ 61,  97, 119],
        [ 59,  95, 117],
        ..., 
        [ 48,  84, 106],
        [ 50,  85, 105],
        [ 51,  86, 106]],

       [[ 66, 102, 124],
        [ 66, 102, 124],
        [ 65, 101, 125],
        ..., 
        [ 48,  84, 106],
        [ 50,  85, 105],
        [ 51,  86, 106]],

       ..., 
       [[ 69, 106, 135],
        [ 66, 103, 132],
        [ 61,  98, 127],
        ..., 
        [ 49,  85, 111],
        [ 51,  87, 113],
        [ 53,  89, 115]],

       [[ 59,  98, 127],
        [ 57,  96, 125],
        [ 56,  95, 124],
        ..., 
        [ 51,  85, 113],
        [ 52,  86, 114],
        [ 53,  87, 115]],

       [[ 63, 102, 131],
        [ 62, 101, 130],
        [ 60, 101, 129],
        ..., 
        [ 53,  86, 117],
        [ 52,  85, 116],
        [ 51,  84, 115]]], dtype=uint8)

我想知道第三维意味着什么?它是一个长度为3的数组(上面输出中的每一行)。

1 个答案:

答案 0 :(得分:5)

红色,绿色和蓝色通道,自然。