我正在尝试使用带有自定义标记的PIL保存TIFF图像。
import numpy as np
import PIL
numrows=10
numcols=10
data = np.random.randint(0, 255, (numrows,numcols)).astype(np.uint8)
rawtiff=PIL.Image.fromarray(data)
custtifftags={'Photometric':1, 'Compression':1, 'BitsPerSample':32,\
'SamplePerPixel':1, 'SampleFormat':3,'ImageLength':10,\
'ImageWidth':10, 'PlanarConfiguration':1, 'ResolutionUnit':2}
rawtiff.save('test.tiff', tiffinfo=custtifftags)我收到以下错误:
TypeError: '<' not supported between instances of 'str' and 'int'导致此错误的原因是什么?如何在设置自己的标记时使用PIL保存图像?
发布于 2020-12-17 05:47:25
我想通了。您需要设置TIFF标记的格式,如下所示:
custtifftags={262:(1,), 259:(0,), 258:(32,),\
277:(1,), 339:(3,),257:(10,),\
256:(10,), 284:(1,), 296:(2,)}发布于 2021-08-03 11:50:00
TIFF不是通过名称来定义标记,而是仅通过数值来定义。为方便起见,请按字母顺序命名。在TiffTags中,您可以找到在PIL中使用的字母值。
作为解决方案,您可以尝试:
from PIL.TiffImagePlugin import ImageFileDirectory_v2
custtifftags = ImageFileDirectory_v2()
custtifftags[101] = 'Test Data 101'https://stackoverflow.com/questions/65308603
复制相似问题