[英]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). 我将图像转换为numpy数组,它返回3D数组而不是2D(宽度和高度)。
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: 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)
I'm wondering what does the 3rd dimension mean? 我想知道第三维意味着什么? It is an array of length 3 (each line in the output above). 它是一个长度为3的数组(上面输出中的每一行)。
红色,绿色和蓝色通道,自然而然。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.