|
2 | 2 | from typing import Tuple |
3 | 3 |
|
4 | 4 | import imageio.v3 as imageio |
5 | | -from skimage.data import binary_blobs |
| 5 | +import requests |
| 6 | +from skimage.data import binary_blobs, cells3d |
6 | 7 | from skimage.measure import label |
7 | 8 |
|
8 | 9 | from .segmentation.postprocessing import _compute_table |
9 | 10 |
|
| 11 | +SEGMENTATION_URL = "https://owncloud.gwdg.de/index.php/s/kwoGRYiJRRrswgw/download" |
10 | 12 |
|
11 | | -def create_image_data_and_segmentation( |
12 | | - folder: str, size: int = 256 |
13 | | -) -> Tuple[str, str, str]: |
| 13 | + |
| 14 | +def get_test_volume_and_segmentation(folder: str) -> Tuple[str, str, str]: |
| 15 | + os.makedirs(folder, exist_ok=True) |
| 16 | + |
| 17 | + segmentation_path = os.path.join(folder, "segmentation.tif") |
| 18 | + resp = requests.get(SEGMENTATION_URL) |
| 19 | + resp.raise_for_status() |
| 20 | + |
| 21 | + with open(segmentation_path, "wb") as f: |
| 22 | + f.write(resp.content) |
| 23 | + |
| 24 | + nuclei = cells3d()[20:40, 1] |
| 25 | + segmentation = imageio.imread(segmentation_path) |
| 26 | + assert nuclei.shape == segmentation.shape |
| 27 | + |
| 28 | + image_path = os.path.join(folder, "image.tif") |
| 29 | + imageio.imwrite(image_path, nuclei) |
| 30 | + |
| 31 | + table_path = os.path.join(folder, "default.tsv") |
| 32 | + table = _compute_table(segmentation, resolution=0.38) |
| 33 | + table.to_csv(table_path, sep="\t", index=False) |
| 34 | + |
| 35 | + return image_path, segmentation_path, table_path |
| 36 | + |
| 37 | + |
| 38 | +def create_image_data_and_segmentation(folder: str, size: int = 256) -> Tuple[str, str, str]: |
14 | 39 | """Create test data containing an image, a corresponding segmentation and segmentation table. |
15 | 40 |
|
16 | 41 | Args: |
|
0 commit comments