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}')
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'])
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}')
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'])