Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions src/bio_image_datasets/pathocell2_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,31 +179,31 @@ def get_class_mapping(self):
return coarse_mapping

def get_instance_mask(self, idx):
"""Return the cell instance mask at the given index.
"""Return the nuclei instance mask at the given index.

In this dataset, instance files can be provided as separate cell and nuclei masks,
so the cell mask is treated as the primary instance mask and the nuclei mask is
exposed separately via get_nuclei_mask().
so the nuclei mask is treated as the primary instance mask and the cell mask is
exposed separately via get_cell_mask().
"""
if idx >= len(self):
raise IndexError("Index out of bounds.")

sample_name = self.sample_names[idx]
cell_path, _ = self._get_instance_mask_paths(sample_name)
if cell_path is not None:
return self._load_mask_from_path(cell_path)
_, nuclei_path = self._get_instance_mask_paths(sample_name)
if nuclei_path is not None:
return self._load_mask_from_path(nuclei_path)
return self._load_mask(self.instance_dir, idx)

def get_nuclei_mask(self, idx):
"""Return the nuclei instance mask at the given index if it exists."""
def get_cell_mask(self, idx):
"""Return the cell instance mask at the given index if it exists."""
if idx >= len(self):
raise IndexError("Index out of bounds.")

sample_name = self.sample_names[idx]
_, nuclei_path = self._get_instance_mask_paths(sample_name)
if nuclei_path is None:
cell_path, _ = self._get_instance_mask_paths(sample_name)
if cell_path is None:
return None
return self._load_mask_from_path(nuclei_path)
return self._load_mask_from_path(cell_path)

def _load_mask_from_path(self, path):
"""Load a single mask from a TIFF path and sanitize its dimensionality."""
Expand Down
4 changes: 2 additions & 2 deletions tests/test_pathocell2_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,11 @@ def test_get_semantic_mask():
assert semantic_mask.shape == (32, 32)


def test_get_nuclei_mask():
def test_get_cell_mask():
with tempfile.TemporaryDirectory() as tmp_dir:
prepare_pathocell2_samples(tmp_dir, num_samples=4)
dataset = PathoCell2Dataset(local_path=tmp_dir)
assert dataset.get_nuclei_mask(0) is None
assert dataset.get_cell_mask(0) is None


def test_get_sample_name():
Expand Down
Loading