简体   繁体   中英

Python: converted matrix from an image is 3D instead of 2D

I converted an image to numpy array and it returned a 3D array instead of 2D (width and height).

My code is:

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)

The 3D matrix looks like:

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)

I'm wondering what does the 3rd dimension mean? It is an array of length 3 (each line in the output above).

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM