@@ -1507,48 +1507,3 @@ def mask_to_labelme(
15071507 }
15081508 with open (output_file .as_posix (), "w" ) as fp :
15091509 json .dump (payload , fp , indent = 2 )
1510-
1511-
1512- def get_channel_names_from_ome_tiff (ome_tiff_file : tp .Union [str , Path ]) -> tp .List [str ]:
1513- """
1514- Parse channel names from OME metadata in OME-TIFF file.
1515- Assumes hierarchy of OME metadata is OME->Image->[Description->]Pixels->Channel.
1516- The "Name" attribute of Channel is returned.
1517-
1518- Parameters
1519- ----------
1520- ome_tiff_file: str | Path
1521- Either a pathlib.Path to a file or a string with OME XML information.
1522-
1523- Returns
1524- -------
1525- list[str]
1526- A list of channel names
1527- """
1528- from xml .etree import ElementTree
1529-
1530- if isinstance (ome_tiff_file , Path ):
1531- f = tifffile .TiffFile (ome_tiff_file )
1532- root = ElementTree .fromstring (f .ome_metadata )
1533- else :
1534- root = ElementTree .fromstring (ome_tiff_file )
1535-
1536- # "OME" is the tag of the root
1537- path_to_channels = ["Image" , "Description" , "Pixels" ]
1538-
1539- i = 0
1540- t = 0
1541- obj = root
1542- while i < len (path_to_channels ):
1543- for c in obj :
1544- tag = c .tag .split ("}" )[- 1 ]
1545- if tag == path_to_channels [i ]:
1546- obj = c
1547- i += 1
1548- t += 1
1549-
1550- # If loop not working, most likely XML does not have the "Description" tag, so try skipping it
1551- if (t > 200 ) and (i == 1 ):
1552- path_to_channels = ["Image" , "Pixels" ]
1553- channels = [c .attrib ["Name" ] for c in obj if c .tag .split ("}" )[- 1 ] == "Channel" ]
1554- return channels
0 commit comments