2015-09-18 239 views
3

我將圖像轉換爲numpy數組,並返回3D數組而不是2D(寬度和高度)。Python:從圖像轉換矩陣是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的數組(上面輸出中的每行)。

回答

5

紅色,綠色和藍色通道,自然。

+0

謝謝!這真的有道理! –