Skip to content

Commit

Permalink
Update check scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
anwai98 committed Jan 9, 2025
1 parent 19c8b32 commit e14e240
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
1 change: 1 addition & 0 deletions scripts/datasets/histopathology/check_cryonuseg.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ def check_cryonuseg():
path=os.path.join(ROOT, "cryonuseg"),
patch_shape=(1, 512, 512),
batch_size=1,
split="train",
rater="b1",
download=True,
)
Expand Down
18 changes: 14 additions & 4 deletions torch_em/data/datasets/histopathology/cryonuseg.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,19 @@ def _create_split_csv(path, data_dir, split):
return split_list


def get_cryonuseg_data(path: Union[os.PathLike, str], download: bool = False):
def get_cryonuseg_data(path: Union[os.PathLike, str], download: bool = False) -> str:
"""Download the CryoNuSeg dataset for nucleus segmentation.
Args:
path: Filepath to a folder where the downloaded data will be saved.
download: Whether to download the data if it is not present.
Returns:
The folder where the data is downloaded and preprocessed.
"""
data_dir = os.path.join(path, r"tissue images")
if os.path.exists(os.path.join(path, r"tissue images")):
return
return data_dir

os.makedirs(path, exist_ok=True)
util.download_source_kaggle(
Expand All @@ -65,6 +69,8 @@ def get_cryonuseg_data(path: Union[os.PathLike, str], download: bool = False):
zip_path = os.path.join(path, "segmentation-of-nuclei-in-cryosectioned-he-images.zip")
util.unzip(zip_path=zip_path, dst=path)

return data_dir


def get_cryonuseg_paths(
path: Union[os.PathLike, str],
Expand All @@ -84,7 +90,7 @@ def get_cryonuseg_paths(
List of filepaths to the image data.
List of filepaths to the label data.
"""
get_cryonuseg_data(path, download)
data_dir = get_cryonuseg_data(path, download)

if rater_choice == "b1":
label_dir = r"Annotator 1 (biologist)/"
Expand All @@ -98,8 +104,12 @@ def get_cryonuseg_paths(
# Point to the instance labels folder
label_dir += r"label masks modify"
split_list = _create_split_csv(path, label_dir, split)

# Get the raw and label paths
label_paths = natsorted([os.path.join(path, label_dir, f'{fname}.tif') for fname in split_list])
raw_paths = natsorted([os.path.join(path, r"tissue images", f'{fname}.tif') for fname in split_list])
raw_paths = natsorted([os.path.join(data_dir, f'{fname}.tif') for fname in split_list])

assert len(raw_paths) == len(label_paths) and len(raw_paths) > 0

return raw_paths, label_paths

Expand Down

0 comments on commit e14e240

Please sign in to comment.