I am working with pyvips to test some cropping speeds vs. other packages. I need to access my x and y resolution. I am able to, but for some reason pyvips is rounding to the nearest mm. I opened my TIFF in QGIS and the resolution is 0.009330691929342804433,-0.009330691929342804433
. I am unsure how to capture this number using pyvips.
img = pyvips.Image.new_from_file(ortho, access='sequential')
print(img.xres)
print(img.yres)
output:
1.0 -type='float'
1.0 - type='float'
Edits
Link to get sample image
Using pyvips 8.12
QGIS Image:
EDITS After @jcupitt answer:
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.keys()}
print(meta_dict)
Output:
...'ModelPixelScaleTag': (0.009330691929340133, 0.009330691929339859, 0.0)
Edits After @jcupitt Edits:
Used exifread
, values are also in there:
import exifread
f = open('image.tif', 'rb')
tags = exifread.process_file(f)
for tag in tags.keys():
if tag not in ('JPEGThumbnail', 'TIFFThumbnail', 'Filename', 'EXIF MakerNote'):
print("Key: %s, value %s" % (tag, tags[tag]))
Output:
Key: Image ImageWidth, value 3564
Key: Image ImageLength, value 2640
Key: Image BitsPerSample, value [8, 8, 8, 8]
Key: Image Compression, value Uncompressed
Key: Image PhotometricInterpretation, value 2
Key: Image StripOffsets, value []
Key: Image SamplesPerPixel, value 4
Key: Image RowsPerStrip, value 1
Key: Image StripByteCounts, value []
Key: Image PlanarConfiguration, value 1
Key: Image ExtraSamples, value Unassociated Alpha
Key: Image SampleFormat, value UnsignedUnsignedUnsignedUnsigned
Key: Image Tag 0x830E, value [(0.009330691929340133,), (0.009330691929339859,), (0.0,)]
Key: Image Tag 0x8482, value [(0.0,), (0.0,), (0.0,), (-13646305.785530405,), (5497215.247385725,), (0.0,)]
Key: Image Tag 0x87AF, value [1, 1, 0, 7, 1024, 0, 1, 1, 1025, 0, 1, 1, 1026, 34737, 25, 0, 2049, 34737, 7, 25, 2054, 0, 1, 9102, 3072, 0, 1, 3857, 3076, 0, 1, 9001]
Key: Image Tag 0x87B1, value WGS 84 / Pseudo-Mercator|WGS 84|
Key: Image Tag 0xA480, value <GDALMetadata>
<Item name="acquisitionEndDate">2021-10-08T20:43:00+00:00</Item>
<Item name="acquisitionStartDate">2021-10-08T20:13:00+00:00</Item>
<Item name="isCalibrated">False</Item>
</GDALMetadata>
pyvips
? I've seen your name all over the place.