Search code examples
pythontiffscikit-image

Read tiff tags in Python


I am trying to read the tags of a tiff file in Python. The file is RGB with uint16 values per channel. I am currently using tifffile:

import tifffile

img = tifffile.imread('file.tif')

However, img is a numpy array, which only has pixel values. How can I read, for instance, the x_resolution of the image?


Solution

  • I found an alternative:

    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()