@@ -65,6 +65,61 @@ class WSIReader:
6565
6666 """
6767
68+ @staticmethod
69+ def open (input_img ):
70+ """Return an appropriate :class:`.WSIReader` object.
71+
72+ Args:
73+ input_img (str, pathlib.Path, :class:`numpy.ndarray`, or :obj:WSIReader):
74+ Input to create a WSI object from.
75+ Supported types of input are: `str` and `pathlib.Path` which point to
76+ the location on the disk where image is stored, :class:`numpy.ndarray`
77+ in which the input image in the form of numpy array (HxWxC) is stored,
78+ or :obj:WSIReader which is an already created tiatoolbox WSI handler.
79+ In the latter case, the function directly passes the input_imge to the
80+ output.
81+
82+ Returns:
83+ WSIReader: an object with base :class:`.WSIReader` as base class.
84+
85+ Examples:
86+ >>> from tiatoolbox.wsicore.wsireader import get_wsireader
87+ >>> wsi = get_wsireader(input_img="./sample.svs")
88+
89+ """
90+ if isinstance (input_img , (str , pathlib .Path )):
91+ _ , _ , suffixes = utils .misc .split_path_name_ext (input_img )
92+
93+ if suffixes [- 1 ] in (".npy" ,):
94+ input_img = np .load (input_img )
95+ wsi = VirtualWSIReader (input_img )
96+
97+ elif suffixes [- 2 :] in ([".ome" , ".tiff" ],):
98+ wsi = TIFFWSIReader (input_img )
99+
100+ elif suffixes [- 1 ] in (".jpg" , ".png" , ".tif" ):
101+ wsi = VirtualWSIReader (input_img )
102+
103+ elif suffixes [- 1 ] in (".svs" , ".ndpi" , ".mrxs" ):
104+ wsi = OpenSlideWSIReader (input_img )
105+
106+ elif suffixes [- 1 ] == (".jp2" ):
107+ wsi = OmnyxJP2WSIReader (input_img )
108+
109+ else :
110+ raise FileNotSupported ("Filetype not supported." )
111+ elif isinstance (input_img , np .ndarray ):
112+ wsi = VirtualWSIReader (input_img )
113+ elif isinstance (
114+ input_img , (VirtualWSIReader , OpenSlideWSIReader , OmnyxJP2WSIReader )
115+ ):
116+ # input is already a tiatoolbox wsi handler
117+ wsi = input_img
118+ else :
119+ raise TypeError ("Please input correct image path or an ndarray image." )
120+
121+ return wsi
122+
68123 def __init__ (self , input_img ):
69124 if isinstance (input_img , np .ndarray ):
70125 self .input_path = None
@@ -2187,35 +2242,8 @@ def get_wsireader(input_img):
21872242 >>> wsi = get_wsireader(input_img="./sample.svs")
21882243
21892244 """
2190- if isinstance (input_img , (str , pathlib .Path )):
2191- _ , _ , suffixes = utils .misc .split_path_name_ext (input_img )
2192-
2193- if suffixes [- 1 ] in (".npy" ,):
2194- input_img = np .load (input_img )
2195- wsi = VirtualWSIReader (input_img )
2196-
2197- elif suffixes [- 2 :] in ([".ome" , ".tiff" ],):
2198- wsi = TIFFWSIReader (input_img )
2199-
2200- elif suffixes [- 1 ] in (".jpg" , ".png" , ".tif" ):
2201- wsi = VirtualWSIReader (input_img )
2202-
2203- elif suffixes [- 1 ] in (".svs" , ".ndpi" , ".mrxs" ):
2204- wsi = OpenSlideWSIReader (input_img )
2205-
2206- elif suffixes [- 1 ] == (".jp2" ):
2207- wsi = OmnyxJP2WSIReader (input_img )
2208-
2209- else :
2210- raise FileNotSupported ("Filetype not supported." )
2211- elif isinstance (input_img , np .ndarray ):
2212- wsi = VirtualWSIReader (input_img )
2213- elif isinstance (
2214- input_img , (VirtualWSIReader , OpenSlideWSIReader , OmnyxJP2WSIReader )
2215- ):
2216- # input is already a tiatoolbox wsi handler
2217- wsi = input_img
2218- else :
2219- raise TypeError ("Please input correct image path or an ndarray image." )
2220-
2221- return wsi
2245+ warnings .warn (
2246+ "get_wsireader is deprecated. Please use WSIReader.open instead" ,
2247+ DeprecationWarning ,
2248+ )
2249+ return WSIReader .open (input_img )
0 commit comments