chiasmos
chiasmos

Reputation: 140

Hidden metadata in TIFF files

I'm using a proprietary software to record and export microscope images as TIFF files. When I load the TIFF files in the imaging software, I have access to all imaging settings at the time of recording. However, I don't have the software on my working computer, so I'm trying to access the metadata in another way.

I have tried using some online TIFF viewers that display TIFF tags and I've tried the OME metadata viewer using Bio-Formats. However, both of them show only a part of the metadata that is available through my imaging software. I have also tried accessing the data through pillow to no avail.

from PIL import Image
from PIL.TiffTags import TAGS

def main():
    with Image.open('image.tif') as img:
        for key in img.tag:
            print(key)
            try:
                print(TAGS[key])
            except:
               print("unknown key")

            print(img.tag[key])

My questions are: Why is the metadata missing, where is it stored, and how can I access it? I'm open to using C++, MatLab, or Python libraries if they can get me what I need.

Upvotes: 1

Views: 2253

Answers (2)

Kip Hackman
Kip Hackman

Reputation: 11

You may be able to use the LEADTOOLS SDK to read the metadata inside your TIFF files. The ReadTags() method offers the ability to read any TIFF tag in the file whether it’s a private tag or not.

The API allows you to enumerate all of the tags in the file, both private and standard, in order to find the tags that you are looking for. https://www.leadtools.com/help/sdk/v22/main/clib/working-with-private-tiff-tags.html

See sample code snippet below (Note code snippet is written in C# but APIs for C++ and Java exist too):

string tifFile = @"FILE PATH TO TIFF";

using (RasterCodecs _codecs = new RasterCodecs())
{
    CodecsImageInfo _info = _codecs.GetInformation(tifFile, false);
    RasterImageFormat _format = _info.Format;
    IList<RasterTagMetadata> _tags = null;
    if (RasterCodecs.TagsSupported(_format))
    {
       // If you have a multipage TIFF you just enumerate through the pages and pass in the page number in the second param below.
        _tags = _codecs.ReadTags(tifFile, 1);
    }
    else
        return;

    if (_tags != null)
    {
        foreach (RasterTagMetadata tag in _tags)
        {
            Console.WriteLine($"Id: 0x{tag.Id.ToString("X")}, data length: {tag.GetData().Length}");
        }
    }
}

https://i.sstatic.net/rcEY9.png

Feel free to also take a look at the Tutorial links below for more information. https://www.leadtools.com/help/sdk/v22/tutorials/cdll-read-and-write-tiff-tags-and-comments.html

DISCLOSURE: I am an employee of the company offering this toolkit.

Upvotes: 1

Daweo
Daweo

Reputation: 36450

Why is the metadata missing

Note that TIFF had multiple versions and also additional specifications for example TIFF/EP or TIFF/IT. Moreover TIFF does support so-called Private tags, according to loc.gov

An organization might wish to store information meaningful to only that organization . . . . Tags numbered 32768 or higher, sometimes called private tags, are reserved for that purpose. Upon request, the TIFF administrator . . . will allocate and register one or more private tags for an organization . . . . You do not need to tell the TIFF administrator what you plan to use them for, but giving us this information may help other developers to avoid some duplication of effort.

Upvotes: 0

Related Questions