在Python中读取TIFF图像元数据 [英] Reading tiff image metadata in Python

查看:1300
本文介绍了在Python中读取TIFF图像元数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

How can I read metada, like coordinates, from a TIFF image in Python? I tried foo._getexif() from PIL, but got the message:

AttributeError:"TiffImageFile"对象没有属性"_getexif"

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

是否可以通过PIL获得它?

Is it possible to get it with 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元数据.

_getexif() is only meant to be used with JPEG. JPEG requires unpacking of the metadata, TIFF does not. That said, PIL does not naively read Exif tags or directory (less straightforward) TIFF metadata.

这篇关于在Python中读取TIFF图像元数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆