Here are the standards for a pyramidal ome-tif file: https://docs.openmicroscopy.org/ome-model/5.6.3/ome-tiff/
These files are supported by the tifffile package in python: https://github.com/cgohlke/tifffile/tree/master
Here is the syntax of opening a specific level of one of these pyramidal ome-tif files from their readme: https://github.com/cgohlke/tifffile/blob/ec6be6289db1b8b7327bb98816a764c95b9b7299/README.rst?plain=1#L678-L682
Here is code to make an ome-tif file to use for testing: https://github.com/cgohlke/tifffile/blob/ec6be6289db1b8b7327bb98816a764c95b9b7299/README.rst?plain=1#L631-L674
I can’t seem to find an easy way to just get the number of layers the file has. A simple solution is here:
simple_all_levels.py
from tifffile import imread, imwrite, TiffFile
f = 'temp.ome.tif'
# Make smaller versions of the big tiff
i = 0
while True:
image = imread(f, series=0, level=i)
imwrite(f"L{i}.{f}", image)
i = i + 1
print(i)
Just run this until it crashes, the last i
that prints is the number of layers. But running until crashing is kinda dumb. After some peeping, I found this snippet:
get_layers_weird.py
from tifffile import imread, imwrite, TiffFile
f = 'temp.ome.tif'
tif = TiffFile(f)
list_of_pages = tif.pages.pages[0].pages.pages
print(len(list_of_pages))
This gets me the answer I want, but getting the length of an array of an accession, of an accession of an array’s first member, which is an accession to the accession of a supplementary import seems too obfuscated to be the intended place for this information to be held.
Where should I look in the ome-tif for its number of levels?