我正在尝试从像素数组(numpy.ndarray)中保存图像。假设我的像素数组是 myArray。当我在 Python 解释器中键入 myArray 时,它显示的值如下:
array([[[154, 161, 156],
[154, 161, 156],
[154, 160, 156],
...,
[152, 157, 156],
[151, 156, 155],
[150, 155, 154]],
[[155, 161, 156],
[155, 161, 156],
[155, 161, 156],
...,
[152, 157, 156],
[151, 156, 155],
[150, 155, 154]],
[[155, 161, 156],
[155, 161, 156],
[155, 161, 156],
...,
[152, 157, 156],
[151, 156, 155],
[150, 155, 154]],
...,
[[187, 193, 188],
[187, 193, 188],
[187, 193, 188],
...,
[189, 194, 193],
[189, 194, 193],
[189, 194, 193]],
[[188, 194, 189],
[188, 194, 189],
[188, 194, 189],
...,
[189, 194, 193],
[189, 194, 193],
[189, 194, 193]],
[[188, 194, 189],
[188, 194, 189],
[188, 194, 189],
...,
[189, 194, 193],
[189, 194, 193],
[189, 194, 193]]], dtype=uint8)
但是,当我使用 从此数组创建新图像cv2.imwrite('abc.jpg',myArray)
,然后使用 读取此图像cv2.imread('abc.jpg')
时,新数组看起来不同。它看起来像这样:
array([[[155, 161, 156],
[155, 161, 156],
[155, 161, 156],
...,
[152, 157, 156],
[151, 156, 155],
[150, 155, 154]],
[[155, 161, 156],
[155, 161, 156],
[155, 161, 156],
...,
[152, 157, 156],
[151, 156, 155],
[150, 155, 154]],
[[155, 161, 156],
[155, 161, 156],
[155, 161, 156],
...,
[152, 157, 156],
[151, 156, 155],
[150, 155, 154]],
...,
[[187, 193, 188],
[187, 193, 188],
[187, 193, 188],
...,
[189, 194, 193],
[189, 194, 193],
[189, 194, 193]],
[[188, 194, 189],
[188, 194, 189],
[188, 194, 189],
...,
[189, 194, 193],
[189, 194, 193],
[189, 194, 193]],
[[188, 194, 189],
[188, 194, 189],
[188, 194, 189],
...,
[189, 194, 193],
[189, 194, 193],
[189, 194, 193]]], dtype=uint8)
知道为什么会这样吗?