Unable to read header inside the tiff image file (Python)

Question:

When I tried to code a simple script to read the "integrationLevel" of the header inside tiff image file, it show that "none" in the output

I have tried to code which is shown as below but the output is "none", it should read the value of the "integrationLevel" and store it with show the output in the terminal.

Can pull the tiff image from here (It’s in the GDrive)

import os
import tifffile

folder_path = "Origin file"

for filename in os.listdir(folder_path):
    if filename.endswith(".tif") or filename.endswith(".tiff"):
        file_path = os.path.join(folder_path, filename)
        with tifffile.TiffFile(file_path) as tif:
            tags = tif.pages[0].tags
            integration_tag = tags.get('il')
            integration = integration_tag.value[0] / integration_tag.value[1] if integration_tag else None

            print(f'integration: {integration}')

Asked By: Neko Lim

||

Answers:

In this case the integrationLevel is not stored as a TIFF tag but can be found in the ImageDescription tag, e.g.,:

import tifffile

with tifffile.TiffFile('top_high_1272_3068_92_92_0.tiff') as tif:
    description = tif.pages[0].description

metadata = dict(tuple(line.split('=', 1)) for line in description.splitlines())
print(metadata['integrationLevel'])
Answered By: cgohlke
Categories: questions Tags:
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.