我正在尝试在Python中读取tiff文件的标签。该文件是RGB,每个通道具有 uint16 值。我目前正在使用 tifffile :
import tifffile
img = tifffile.imread('file.tif')
但是,img
是一个仅包含像素值的numpy数组。例如,如何读取图像的 x_resolution ?
答案 0 :(得分:2)
不确定tifffile
库,但可以通过x resolution
获得exifread
:
import exifread
with open('image.tif', 'rb') as f:
tags = exifread.process_file(f)
print(tags['Image XResolution'])
输出:
300
答案 1 :(得分:2)
我找到了另一种选择:
import tifffile
with tifffile.TiffFile('file.tif') as tif:
tif_tags = {}
for tag in tif.pages[0].tags.values():
name, value = tag.name, tag.value
tif_tags[name] = value
image = tif.pages[0].asarray()
答案 2 :(得分:0)
使用skimage.external.tifffile
是另一种可能的方法:
from skimage.external import tifffile
with tifffile.TiffFile('your_file.tif') as tif:
imgs = [page.asarray() for page in tif.pages]
x_res = [page.tags['x_resolution'].value for page in tif.pages]