Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/apache/9.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
用Python在16位灰度图像上写入文本_Python_Numpy_Python Imaging Library - Fatal编程技术网

用Python在16位灰度图像上写入文本

用Python在16位灰度图像上写入文本,python,numpy,python-imaging-library,Python,Numpy,Python Imaging Library,我试图用Python在16位灰度图像上绘制文本。我正在使用Numpy创建我的16位NDI图像 我使用modemode='L' a = np.zeros([rows,columns],dtype=np.uint16) img = Image.fromarray(a,mode='L') .... draw = ImageDraw.Draw(img) for i in range(1,32): draw.text((0,i*height), text + ' ' + str(i), fon

我试图用Python在16位灰度图像上绘制文本。我正在使用Numpy创建我的16位NDI图像

我使用mode
mode='L'

a = np.zeros([rows,columns],dtype=np.uint16)
img = Image.fromarray(a,mode='L')

....

draw = ImageDraw.Draw(img)
for i in range(1,32):
    draw.text((0,i*height), text + ' ' + str(i), font=font, fill=32*i)
它一直工作到我超过255(或8位)。以上填充值为255,所有值在图像中显示为255


是否有办法让PIL处理16位灰度,或者python中是否有其他库允许我在16位图像上写入文本。

您确定您的.fromarray()调用真的提供了所需的位图吗?我尝试用从0到65535的梯度填充“a”数组,但得到的不是我所期望的。似乎每个数组元素(uint16类型)都会在图像中产生两个像素!PIL应该能够处理16位图像。尝试使用模式“L;16”。默认情况下,“L”模式为8位。@gavinb with mode='L;16“我被认不出来了mode@MichielOvertoom对我没有测试过,但我也得到了意想不到的结果。您使用的是哪个版本?AFAICT支持的模式有: