我正在尝试将array
转换为图像(tif)进行压缩(它将在另一端撤消)。然而,我在第一个栏位就摔倒了。。。在
我有以下内容:
pillow_image = Image.fromarray(image_data)
这给了我一个错误:
File "/Users/workspace/test-app/env/lib/python2.7/site-packages/PIL/Image.py",
line 2155, in fromarray arr = obj.array_interface AttributeError: 'tuple' object has no attribute 'array_interface'
我做错什么了?在
image_data
是由4个numpy数组组成的元组,每个数组(可能)都是形状(H,W)。你呢 需要image_data
为单个形状数组(H,W,4)。因此,使用np.dstack组合通道。在至少有一个数组具有dtype int32。但要将其用作8位彩色通道,数组必须是dtype
uint8
(因此最大值为255)。可以使用astype
将数组转换为数据类型uint8
。希望您的数据不包含大于255的值。如果是这样,astype('uint8')
将只保留最低有效位(即返回数字模256)。在相关问题 更多 >
编程相关推荐