|
11 | 11 | import pooch |
12 | 12 |
|
13 | 13 |
|
14 | | -def fetch_image_series_example_data(save_directory: Union[str, os.PathLike]) -> Union[str, os.PathLike]: |
15 | | - """Download the sample images for the image series annotator. |
16 | | -
|
17 | | - Args: |
18 | | - save_directory: Root folder to save the downloaded data. |
19 | | - Returns: |
20 | | - The folder that contains the downloaded data. |
21 | | - """ |
22 | | - save_directory = Path(save_directory) |
23 | | - os.makedirs(save_directory, exist_ok=True) |
24 | | - print("Example data directory is:", save_directory.resolve()) |
25 | | - fname = "image-series.zip" |
26 | | - # use first two files for image series (thrid file is not the same shape) |
27 | | - unpack_filenames = [os.path.join("series", f"im{i}.tif") for i in range(2)] |
28 | | - unpack = pooch.Unzip(members=unpack_filenames) |
29 | | - pooch.retrieve( |
30 | | - url="https://owncloud.gwdg.de/index.php/s/M1zGnfkulWoAhUG/download", |
31 | | - known_hash="92346ca9770bcaf55248efee590718d54c7135b6ebca15d669f3b77b6afc8706", |
32 | | - fname=fname, |
33 | | - path=save_directory, |
34 | | - progressbar=True, |
35 | | - processor=unpack, |
36 | | - ) |
37 | | - data_folder = os.path.join(save_directory, f"{fname}.unzip", "series") |
38 | | - assert os.path.exists(data_folder) |
39 | | - return data_folder |
40 | | - |
41 | | - |
42 | | -def sample_data_image_series(): |
43 | | - """Provides 2d image series example data to napari.""" |
44 | | - # Return list of tuples |
45 | | - # [(data1, add_image_kwargs1), (data2, add_image_kwargs2)] |
46 | | - # Check the documentation for more information about the |
47 | | - # add_image_kwargs |
48 | | - # https://napari.org/stable/api/napari.Viewer.html#napari.Viewer.add_image |
49 | | - default_base_data_dir = pooch.os_cache('micro-sam') |
50 | | - data_directory = fetch_image_series_example_data(default_base_data_dir) |
51 | | - fnames = os.listdir(data_directory) |
52 | | - full_filenames = [os.path.join(data_directory, f) for f in fnames] |
53 | | - full_filenames.sort() |
54 | | - data = np.stack([imageio.imread(f) for f in full_filenames], axis=0) |
55 | | - add_image_kwargs = {"name": "image-series"} |
56 | | - return [(data, add_image_kwargs)] |
57 | | - |
58 | | - |
59 | 14 | def fetch_wholeslide_example_data(save_directory: Union[str, os.PathLike]) -> Union[str, os.PathLike]: |
60 | 15 | """Download the sample data for the 2d annotator. |
61 | 16 |
|
|
0 commit comments