Skip to content
Snippets Groups Projects
Commit 5438fb26 authored by Daniel CARRON's avatar Daniel CARRON :b: Committed by André Anjos
Browse files

[segmentation] Add drishtigs1 database

parent 5c6f8df2
No related branches found
No related tags found
1 merge request!46Create common library
Showing
with 136 additions and 0 deletions
......@@ -440,6 +440,12 @@ drionsdb-2nd = "mednet.libs.segmentation.config.data.drionsdb.expert2"
# drive dataset - retinography
drive = "mednet.libs.segmentation.config.data.drive.default"
# drishti-gs1 - retinography
drishtigs1-disc-all = "mednet.libs.segmentation.config.data.drishtigs1.optic_disc_all"
drishtigs1-disc-any = "mednet.libs.segmentation.config.data.drishtigs1.optic_disc_any"
drishtigs1-cup-all = "mednet.libs.segmentation.config.data.drishtigs1.optic_cup_all"
drishtigs1-cup-any = "mednet.libs.segmentation.config.data.drishtigs1.optic_cup_any"
# iostar - retinography
iostar-vessel = "mednet.libs.segmentation.config.data.iostar.vessel"
iostar-disc = "mednet.libs.segmentation.config.data.iostar.optic_disc"
......
# SPDX-FileCopyrightText: Copyright © 2024 Idiap Research Institute <contact@idiap.ch>
#
# SPDX-License-Identifier: GPL-3.0-or-later
"""Drishti-GS1 for Optic Disc and Cup Segmentation."""
import os
import pathlib
import PIL.Image
import pkg_resources
from mednet.libs.common.data.datamodule import CachingDataModule
from mednet.libs.common.data.split import make_split
from mednet.libs.common.data.typing import Sample
from mednet.libs.common.models.transforms import crop_image_to_mask
from mednet.libs.segmentation.data.typing import (
SegmentationRawDataLoader as _SegmentationRawDataLoader,
)
from torchvision import tv_tensors
from torchvision.transforms.functional import to_tensor
from ....utils.rc import load_rc
CONFIGURATION_KEY_DATADIR = "datadir." + (__name__.rsplit(".", 2)[-2])
"""Key to search for in the configuration file for the root directory of this
database."""
class SegmentationRawDataLoader(_SegmentationRawDataLoader):
"""A specialized raw-data-loader for the drishtigs1 dataset.
Parameters
----------
target_all
Indicate whether to use the "all" or "any" target.
"""
datadir: pathlib.Path
"""This variable contains the base directory where the database raw data is
stored."""
def __init__(self, target_all: bool):
self.datadir = pathlib.Path(
load_rc().get(CONFIGURATION_KEY_DATADIR, os.path.realpath(os.curdir))
)
self._pkg_path = pathlib.Path(
pkg_resources.resource_filename(__name__, "masks")
)
self.target_all = target_all
def sample(self, sample: tuple[str, str, str]) -> Sample:
"""Load a single image sample from the disk.
Parameters
----------
sample
A tuple containing path suffixes to the sample image, target, and mask
to be loaded, within the dataset root folder.
Returns
-------
The sample representation.
"""
image = to_tensor(PIL.Image.open(self.datadir / sample[0]).convert(mode="RGB"))
if self.target_all:
target = to_tensor(
PIL.Image.open(self.datadir / sample[1])
.convert(mode="RGB", dither=None)
.convert("L")
.point(lambda p: p > 254, mode="1")
)
else:
target = to_tensor(
PIL.Image.open(self.datadir / sample[1])
.convert(mode="RGB", dither=None)
.convert("L")
.point(lambda p: p > 0, mode="1")
)
mask = to_tensor(
PIL.Image.open(self._pkg_path / sample[2]).convert(mode="1", dither=None)
)
tensor = tv_tensors.Image(crop_image_to_mask(image, mask))
target = tv_tensors.Image(crop_image_to_mask(target, mask))
mask = tv_tensors.Mask(crop_image_to_mask(mask, mask))
return tensor, dict(target=target, mask=mask, name=sample[0]) # type: ignore[arg-type]
class DataModule(CachingDataModule):
"""Drishti-GS1 for Optic Disc and Cup Segmentation.
Drishti-GS is a dataset meant for validation of segmenting OD, cup and
detecting notching. The images in the Drishti-GS dataset have been collected
and annotated by Aravind Eye hospital, Madurai, India. This dataset is of a
single population as all subjects whose eye images are part of this dataset are
Indians.
The dataset is divided into two: a training set and a testing set of images.
Training images (50) are provided with groundtruths for OD and Cup segmentation
and notching information.
* Reference (including train/test split): [DRISHTIGS1-2014]_
* Original resolution (height x width): varying (min: 1749 x 2045, max: 1845 x
2468)
* Configuration resolution: 1760 x 2048 (after center cropping)
* Protocols ``optic-disc`` and ``optic-cup``:
* Training: 50
* Test: 51
Parameters
----------
split_filename
Name of the .json file containing the split to load.
target_all
Indicate whether to use the "all" or "any" target.
"""
def __init__(self, split_filename: str, target_all: bool):
assert __package__ is not None
super().__init__(
database_split=make_split(__package__, split_filename),
raw_data_loader=SegmentationRawDataLoader(target_all),
database_name=__package__.rsplit(".", 1)[1],
split_name=pathlib.Path(split_filename).stem,
)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment