Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/image/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Image 用numpy阵列进行图像处理_Image_Pillow - Fatal编程技术网

Image 用numpy阵列进行图像处理

Image 用numpy阵列进行图像处理,image,pillow,Image,Pillow,在灰度模式下,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位有符号整数像素) (注意:非常感谢您通过本文向我介绍Python枕

在灰度模式下,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位有符号整数像素)

(注意:非常感谢您通过本文向我介绍Python枕头图像模块…)

完整的测试代码:

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

证实。。我在Windows10上使用Canopy/ipython获得了相同的结果。奇怪的是,当我将数组大小更改为185185时,所有的线都是对角的。184184=垂直线。是的,我的项目因此无法运行,最后经过大量调试,我发现这是问题,我使用image.convert('L')将其更改为所需的灰度模式,即j.convert('L'))