使用 numpy 数组进行图像处理

Image processing with numpy arrays

灰度模式下,255表示白色。那么如果numpy矩阵的所有元素都是255,那不应该是一张白图吗?

l = np.full((184,184),255)
j = Image.fromarray(l,'L')
j.show()

我得到的是黑白垂直条纹图像作为输出,而不是纯白色图像。为什么会这样?

问题是 'L' 模式。 L = 8 位像素,黑色和白色。您创建的数组可能是 32 位值。

尝试j = Image.fromarray(l, 'I') ## (32-bit signed integer pixels)

reference.

(注意:非常感谢您通过此帖子向我介绍 Python 的 Pillow Image 模块...)

完整的测试代码:

from PIL import Image
import numpy as np
l = np.full((184,184),255)
j = Image.fromarray(m, 'I')
j.show()