【发布时间】:2020-10-30 14:52:18
【问题描述】:
部分问题在于 Pillow 的 ReadtheDocs 已关闭,而 GoogleFu 让我无处可去...
注解为“大黑”框(图章)样式。
所以我们有一个 TIFF 文件和一个 ANN 文件。我相信注释 (ANN) 文件是我尝试重新添加到原始 tiff 文件中的 TIFF 注释的提取 TAG 信息。
>>> im = Image.open(test)
>>> im2 = Image.open(test2)
>>> meta_dict = {TAGS[key] : im2.tag[key] for key in im2.tag.keys()}
>>> meta_dict
{'ImageWidth': (2544,), 'ImageLength': (0,), 'BitsPerSample': (1,), 'Compression': (1,), 'PhotometricInterpretation': (0,), 'StripOffsets': (0,), 'Orientation': (1,), 'SamplesPerPixel': (1,), 'RowsPerStrip': (0,), 'StripByteCounts': (0,), 'XResolution': ((300, 1),), 'YResolution': ((300, 1),), 'Wang Annotation': b'\x04\x00\x03\x00\x01\x00\x00\x00\x02\x00\x00\x00\x0c\x00\x00\x00OiGroup\x00\x0b\x00\x00\x00[Untitled]\x00\x02\x00\x00\x00\x0c\x00\x00\x00OiIndex\x00\n\x00\x00\x000\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00\x0c\x00\x00\x00PxVerStr\r\x00\x00\x0056.1.11.1571\x00\x02\x00\x00\x00\x0c\x00\x00\x00PxDPI\x00\x00\x00\x10\x00\x00\x00\xc8\x00\x00\x00\x01\x00\x00\x00\xc8\x00\x00\x00\x01\x00\x00\x00\x02\x00\x00\x00\x0c\x00\x00\x00PxStorag\x04\x00\x00\x00\x00\x00\x00\x00', 'ResolutionUnit': (2,), 'Software': ('Pixel Translations Inc., PIXTIFF Version 56.1.218.1571',), 'NewSubfileType': (0,)}
>>> im.tag[32932] = meta_dict["Wang Annotation"]
>>> im.save("test.tif")
>>> im.show()
通过阅读StackOverflow等,我认为上面的代码足以将注释从im2“合并”到im1?但是我没看到……
How to add additional Tag for tiff file
你能给我一些关于我哪里出错的建议吗?
【问题讨论】:
-
第三行可以改写为
meta_dict = {TAGS[key] : value for key, value in im2.tag.items()}
标签: annotations python-imaging-library tiff