66from pathlib import Path
77from typing import Union
88
9+ import imageio .v3 as imageio
10+ import numpy as np
911import pooch
1012
1113
@@ -17,6 +19,9 @@ def fetch_image_series_example_data(save_directory: Union[str, os.PathLike]) ->
1719 Returns:
1820 The folder that contains the downloaded data.
1921 """
22+ # This sample dataset is currently not provided to napari by the micro-sam
23+ # plugin, because images are not all the same shape and cannot be combined
24+ # into a single layer
2025 save_directory = Path (save_directory )
2126 os .makedirs (save_directory , exist_ok = True )
2227 print ("Example data directory is:" , save_directory .resolve ())
@@ -36,6 +41,26 @@ def fetch_image_series_example_data(save_directory: Union[str, os.PathLike]) ->
3641 return data_folder
3742
3843
44+ def sample_data_image_series ():
45+ """Provides image series example image to napari.
46+
47+ Opens as three separate image layers in napari (one per image in series).
48+ The third image in the series has a different size and modality.
49+ """
50+ # Return list of tuples
51+ # [(data1, add_image_kwargs1), (data2, add_image_kwargs2)]
52+ # Check the documentation for more information about the
53+ # add_image_kwargs
54+ # https://napari.org/stable/api/napari.Viewer.html#napari.Viewer.add_image
55+ default_base_data_dir = pooch .os_cache ('micro-sam' )
56+ data_directory = fetch_image_series_example_data (default_base_data_dir )
57+ fnames = os .listdir (data_directory )
58+ full_filenames = [os .path .join (data_directory , f ) for f in fnames ]
59+ full_filenames .sort ()
60+ data_and_image_kwargs = [(imageio .imread (f ), {"name" : f"img-{ i } " }) for i , f in enumerate (full_filenames )]
61+ return data_and_image_kwargs
62+
63+
3964def fetch_wholeslide_example_data (save_directory : Union [str , os .PathLike ]) -> str :
4065 """Download the sample data for the 2d annotator.
4166
@@ -61,6 +86,20 @@ def fetch_wholeslide_example_data(save_directory: Union[str, os.PathLike]) -> st
6186 return os .path .join (save_directory , fname )
6287
6388
89+ def sample_data_wholeslide ():
90+ """Provides wholeslide 2d example image to napari."""
91+ # Return list of tuples
92+ # [(data1, add_image_kwargs1), (data2, add_image_kwargs2)]
93+ # Check the documentation for more information about the
94+ # add_image_kwargs
95+ # https://napari.org/stable/api/napari.Viewer.html#napari.Viewer.add_image
96+ default_base_data_dir = pooch .os_cache ('micro-sam' )
97+ filename = fetch_wholeslide_example_data (default_base_data_dir )
98+ data = imageio .imread (filename )
99+ add_image_kwargs = {"name" : "wholeslide" }
100+ return [(data , add_image_kwargs )]
101+
102+
64103def fetch_livecell_example_data (save_directory : Union [str , os .PathLike ]) -> str :
65104 """Download the sample data for the 2d annotator.
66105
@@ -74,7 +113,6 @@ def fetch_livecell_example_data(save_directory: Union[str, os.PathLike]) -> str:
74113 """
75114 save_directory = Path (save_directory )
76115 os .makedirs (save_directory , exist_ok = True )
77- print ("Example data directory is:" , save_directory .resolve ())
78116 fname = "livecell-2d-image.png"
79117 pooch .retrieve (
80118 url = "https://owncloud.gwdg.de/index.php/s/fSaOJIOYjmFBjPM/download" ,
@@ -86,7 +124,21 @@ def fetch_livecell_example_data(save_directory: Union[str, os.PathLike]) -> str:
86124 return os .path .join (save_directory , fname )
87125
88126
89- def fetch_hela_2d_example_data (save_directory : Union [str , os .PathLike ]) -> str :
127+ def sample_data_livecell ():
128+ """Provides livecell 2d example image to napari."""
129+ # Return list of tuples
130+ # [(data1, add_image_kwargs1), (data2, add_image_kwargs2)]
131+ # Check the documentation for more information about the
132+ # add_image_kwargs
133+ # https://napari.org/stable/api/napari.Viewer.html#napari.Viewer.add_image
134+ default_base_data_dir = pooch .os_cache ('micro-sam' )
135+ filename = fetch_livecell_example_data (default_base_data_dir )
136+ data = imageio .imread (filename )
137+ add_image_kwargs = {"name" : "livecell" }
138+ return [(data , add_image_kwargs )]
139+
140+
141+ def fetch_hela_2d_example_data (save_directory : Union [str , os .PathLike ]) -> Union [str , os .PathLike ]:
90142 """Download the sample data for the 2d annotator.
91143
92144 This downloads a single image from the HeLa CTC dataset.
@@ -110,6 +162,20 @@ def fetch_hela_2d_example_data(save_directory: Union[str, os.PathLike]) -> str:
110162 return os .path .join (save_directory , fname )
111163
112164
165+ def sample_data_hela_2d ():
166+ """Provides HeLa 2d example image to napari."""
167+ # Return list of tuples
168+ # [(data1, add_image_kwargs1), (data2, add_image_kwargs2)]
169+ # Check the documentation for more information about the
170+ # add_image_kwargs
171+ # https://napari.org/stable/api/napari.Viewer.html#napari.Viewer.add_image
172+ default_base_data_dir = pooch .os_cache ("micro-sam" )
173+ filename = fetch_hela_2d_example_data (default_base_data_dir )
174+ data = imageio .imread (filename )
175+ add_image_kwargs = {"name" : "hela_2d" }
176+ return [(data , add_image_kwargs )]
177+
178+
113179def fetch_3d_example_data (save_directory : Union [str , os .PathLike ]) -> str :
114180 """Download the sample data for the 3d annotator.
115181
@@ -139,6 +205,23 @@ def fetch_3d_example_data(save_directory: Union[str, os.PathLike]) -> str:
139205 return str (lucchi_dir )
140206
141207
208+ def sample_data_3d ():
209+ """Provides Lucchi++ 3d example image to napari."""
210+ # Return list of tuples
211+ # [(data1, add_image_kwargs1), (data2, add_image_kwargs2)]
212+ # Check the documentation for more information about the
213+ # add_image_kwargs
214+ # https://napari.org/stable/api/napari.Viewer.html#napari.Viewer.add_image
215+ default_base_data_dir = pooch .os_cache ("micro-sam" )
216+ data_directory = fetch_3d_example_data (default_base_data_dir )
217+ fnames = os .listdir (data_directory )
218+ full_filenames = [os .path .join (data_directory , f ) for f in fnames ]
219+ full_filenames .sort ()
220+ data = np .stack ([imageio .imread (f ) for f in full_filenames ], axis = 0 )
221+ add_image_kwargs = {"name" : "lucchi++" }
222+ return [(data , add_image_kwargs )]
223+
224+
142225def fetch_tracking_example_data (save_directory : Union [str , os .PathLike ]) -> str :
143226 """Download the sample data for the tracking annotator.
144227
@@ -156,7 +239,6 @@ def fetch_tracking_example_data(save_directory: Union[str, os.PathLike]) -> str:
156239 """
157240 save_directory = Path (save_directory )
158241 os .makedirs (save_directory , exist_ok = True )
159- print ("Example data directory is:" , save_directory .resolve ())
160242 unpack_filenames = [os .path .join ("DIC-C2DH-HeLa" , "01" , f"t{ str (i ).zfill (3 )} .tif" ) for i in range (84 )]
161243 unpack = pooch .Unzip (members = unpack_filenames )
162244 fname = "DIC-C2DH-HeLa.zip"
@@ -173,6 +255,23 @@ def fetch_tracking_example_data(save_directory: Union[str, os.PathLike]) -> str:
173255 return str (cell_tracking_dir )
174256
175257
258+ def sample_data_tracking ():
259+ """Provides tracking example dataset to napari."""
260+ # Return list of tuples
261+ # [(data1, add_image_kwargs1), (data2, add_image_kwargs2)]
262+ # Check the documentation for more information about the
263+ # add_image_kwargs
264+ # https://napari.org/stable/api/napari.Viewer.html#napari.Viewer.add_image
265+ default_base_data_dir = pooch .os_cache ("micro-sam" )
266+ data_directory = fetch_tracking_example_data (default_base_data_dir )
267+ fnames = os .listdir (data_directory )
268+ full_filenames = [os .path .join (data_directory , f ) for f in fnames ]
269+ full_filenames .sort ()
270+ data = np .stack ([imageio .imread (f ) for f in full_filenames ], axis = 0 )
271+ add_image_kwargs = {"name" : "tracking" }
272+ return [(data , add_image_kwargs )]
273+
274+
176275def fetch_tracking_segmentation_data (save_directory : Union [str , os .PathLike ]) -> str :
177276 """Download groundtruth segmentation for the tracking example data.
178277
@@ -200,3 +299,20 @@ def fetch_tracking_segmentation_data(save_directory: Union[str, os.PathLike]) ->
200299 cell_tracking_dir = save_directory .joinpath (f"{ fname } .unzip" , "masks" )
201300 assert os .path .exists (cell_tracking_dir )
202301 return str (cell_tracking_dir )
302+
303+
304+ def sample_data_segmentation ():
305+ """Provides segmentation example dataset to napari."""
306+ # Return list of tuples
307+ # [(data1, add_image_kwargs1), (data2, add_image_kwargs2)]
308+ # Check the documentation for more information about the
309+ # add_image_kwargs
310+ # https://napari.org/stable/api/napari.Viewer.html#napari.Viewer.add_image
311+ default_base_data_dir = pooch .os_cache ("micro-sam" )
312+ data_directory = fetch_tracking_segmentation_data (default_base_data_dir )
313+ fnames = os .listdir (data_directory )
314+ full_filenames = [os .path .join (data_directory , f ) for f in fnames ]
315+ full_filenames .sort ()
316+ data = np .stack ([imageio .imread (f ) for f in full_filenames ], axis = 0 )
317+ add_image_kwargs = {"name" : "segmentation" }
318+ return [(data , add_image_kwargs )]
0 commit comments