python - 在 Python 中读取 tiff 图像元数据

标签 python python-imaging-library tiff

如何从 Python 中的 TIFF 图像中读取元数据(如坐标)?我尝试了 PIL 的 foo._getexif(),但收到了消息:

AttributeError: 'TiffImageFile' object has no attribute '_getexif'

是否可以通过 PIL 获取它?

最佳答案

from PIL import Image
from PIL.TiffTags import TAGS

with Image.open('image.tif') as img:
    meta_dict = {TAGS[key] : img.tag[key] for key in img.tag.iterkeys()}

_getexif() 仅适用于 JPEG。 JPEG 需要解包元数据,而 TIFF 不需要。也就是说,PIL 不会天真地读取 Exif 标签或目录(不太直接)TIFF 元数据。

关于python - 在 Python 中读取 tiff 图像元数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46477712/

相关文章:

python - 循环中嵌套字典

python - 如何使用 youtube-dl 获取视频信息,无需下载

python - 如何在枕头中使用 alpha_composite?

python - PIL 不会导入_imaging C 模块 : "*** The _imaging C module is not installed"

c# - 如何使用 LibTiff.Net 2.3 库删除 tiff 标签

linux - 如何使用 GhostScript 避免标题截断 tiff。选择 于 tiff

python - 从 pandas 数据框中的唯一条目创建字典

python - 使用 SQLObject ORM 筛选 "value in list"

python - Pillow 中 float 图像的堆叠线图

c# - 将 tiff 像素长宽比更改为正方形