【问题标题】:Adding a WANG Annotation to an existing TIFF image w/Python & PILLOW使用 Python 和 PILLOW 向现有 TIFF 图像添加 WANG 注释
【发布时间】: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


【解决方案1】:

您似乎错过了tiffinfo 参数。尝试像这样保存文件:

im.save("test.tif", tiffinfo=im.tag)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-10-30
    • 2021-10-28
    • 2013-05-21
    • 1970-01-01
    • 2018-04-23
    • 1970-01-01
    • 2014-04-18
    相关资源
    最近更新 更多