Skip to content

Instantly share code, notes, and snippets.

@jmuhlich
Created April 22, 2020 21:42
Show Gist options
  • Save jmuhlich/b0f992d7c146e06d9609c04572952847 to your computer and use it in GitHub Desktop.
Save jmuhlich/b0f992d7c146e06d9609c04572952847 to your computer and use it in GitHub Desktop.
ometiff-channel-names.py
import sys
import io
import warnings
import xml.etree.ElementTree
import tifffile
if len(sys.argv) != 2:
print(f"Usage: ometiff-channel-names.py input.ome.tif")
print("Print the channel names for the first image in an OME-TIFF file.")
sys.exit(1)
ometiff_path = sys.argv[1]
tiff = tifffile.TiffFile(ometiff_path)
omexml_string = tiff.pages[0].description
root = xml.etree.ElementTree.parse(io.StringIO(omexml_string))
namespaces = {'ome': 'http://www.openmicroscopy.org/Schemas/OME/2016-06'}
channels = root.findall('ome:Image[1]/ome:Pixels/ome:Channel', namespaces)
channel_names = [c.attrib['Name'] for c in channels]
for n in channel_names:
print(n)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment