66from trident .wsi_objects .ImageWSI import ImageWSI
77from trident .wsi_objects .CuCIMWSI import CuCIMWSI
88from trident .wsi_objects .SDPCWSI import SDPCWSI
9- WSIReaderType = Literal ['openslide' , 'image' , 'cucim' , 'sdpc' ]
9+ from trident .wsi_objects .OMEZarrWSI import OMEZarrWSI
10+ WSIReaderType = Literal ['openslide' , 'image' , 'cucim' , 'sdpc' , 'omezarr' ]
1011OPENSLIDE_EXTENSIONS = {'.svs' , '.tif' , '.tiff' , '.ndpi' , '.vms' , '.vmu' , '.scn' , '.mrxs' }
1112CUCIM_EXTENSIONS = {'.svs' , '.tif' , '.tiff' }
1213SDPC_EXTENSIONS = {'.sdpc' }
1314PIL_EXTENSIONS = {'.png' , '.jpg' , '.jpeg' }
15+ OMEZARR_EXTENSIONS = {'.ome.zarr' }
1416
1517
1618def load_wsi (
1719 slide_path : str ,
1820 reader_type : Optional [WSIReaderType ] = None ,
1921 lazy_init : bool = False ,
2022 ** kwargs
21- ) -> Union [OpenSlideWSI , ImageWSI , CuCIMWSI , SDPCWSI ]:
23+ ) -> Union [OpenSlideWSI , ImageWSI , CuCIMWSI , SDPCWSI , OMEZarrWSI ]:
2224 """
2325 Load a whole-slide image (WSI) using the appropriate backend.
2426
@@ -30,7 +32,7 @@ def load_wsi(
3032 ----------
3133 slide_path : str
3234 Path to the whole-slide image.
33- reader_type : {'openslide', 'image', 'cucim', 'sdpc'}, optional
35+ reader_type : {'openslide', 'image', 'cucim', 'sdpc', 'omezarr' }, optional
3436 Manually specify the WSI reader to use. If None (default), selection
3537 is automatic based on file extension.
3638 lazy_init : bool, optional
@@ -41,7 +43,7 @@ def load_wsi(
4143
4244 Returns
4345 -------
44- Union[OpenSlideWSI, ImageWSI, CuCIMWSI, SDPCWSI]
46+ Union[OpenSlideWSI, ImageWSI, CuCIMWSI, SDPCWSI, OMEZarrWSI ]
4547 An instance of the appropriate WSI reader.
4648
4749 Raises
@@ -78,11 +80,22 @@ def load_wsi(
7880 f"Unsupported file format '{ ext } ' for CuCIM. "
7981 f"Supported whole-slide image formats are: { ', ' .join (CUCIM_EXTENSIONS )} ."
8082 )
81-
83+
84+ elif reader_type == 'omezarr' :
85+ if ext in OMEZARR_EXTENSIONS :
86+ return OMEZarrWSI (slide_path = slide_path , lazy_init = lazy_init , ** kwargs )
87+ else :
88+ raise ValueError (
89+ f"Unsupported file format '{ ext } ' for Ome-Zarr. "
90+ f"Supported whole-slide image formats are: { ', ' .join (OMEZARR_EXTENSIONS )} ."
91+ )
92+
8293 elif reader_type is None :
8394 if ext in OPENSLIDE_EXTENSIONS :
8495 return OpenSlideWSI (slide_path = slide_path , lazy_init = lazy_init , ** kwargs )
8596 elif ext in SDPC_EXTENSIONS :
8697 return SDPCWSI (slide_path = slide_path , lazy_init = lazy_init , ** kwargs )
98+ elif ext in OMEZARR_EXTENSIONS :
99+ return OMEZarrWSI (slide_path = slide_path , lazy_init = lazy_init , ** kwargs )
87100 else :
88101 return ImageWSI (slide_path = slide_path , lazy_init = lazy_init , ** kwargs )
0 commit comments