PIL或Pillow能否在TIFF文件中获得目录0的偏移量?

2024-04-29 03:57:54 发布

您现在位置:Python中文网/ 问答频道 /正文

我想从TIFF图像文件目录中获取目录偏移量值。PIL/Pillow和其他软件包可以为我获取tiff标签,但是这个值不是来自tiff标签,而是来自IFD标题。你知道吗

这是一个使用python3.7的Ubuntu项目。我只想得到IFD偏移值。你知道吗

在提示下,我会这样做:

tiffdump 1.tif
1.tif:
Magic: 0x4949 <little-endian> Version: 0x2a <ClassicTIFF>
Directory 0: offset 10216 (0x27e8) next 12902 (0x3266)
SubFileType (254) LONG (4) 1<0>
ImageWidth (256) SHORT (3) 1<1187>
ImageLength (257) SHORT (3) 1<552>
.
.
.

10216是我想要的。你知道吗

PIL/Pillow(据我所知)使用libtiff做一些类似的事情来获得tiff标签。但该值不在tiff标记中。对于某些文件,STripBytecounts+stripOffset为我提供了正确的IFD偏移量,但这不是确定的:

# get offset for x.tif
im = Image.open(final_dataset + str(x) + ".tif")
tag_dict = im.tag_v2
StripByteCounts = (tag_dict.get(279))
StripOffsets = (tag_dict.get(273))
tiff_directory_offset = (StripByteCounts[0] + StripOffsets[0])

我怀疑为了得到我想要的价值,我错过了一些非常简单的东西。有什么想法吗?你知道吗


Tags: getpiltag标签dictoffset偏移量short