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

[segmentation] Add chasedb1 database

parent 32440226
No related branches found
No related tags found
1 merge request!46Create common library
Showing
with 296 additions and 1 deletion
......@@ -423,8 +423,14 @@ visceral = "mednet.config.data.visceral.default"
lwnet = "mednet.libs.segmentation.config.models.lwnet"
# drive dataset - retinal vessel segmentation
# chase-db1 - retinography
chasedb1 = "mednet.libs.segmentation.config.data.chasedb1.first_annotator"
chasedb1-2nd = "mednet.libs.segmentation.config.data.chasedb1.second_annotator"
# drive dataset - retinography
drive = "mednet.libs.segmentation.config.data.drive.default"
# stare dataset - retinography
stare = "mednet.libs.segmentation.config.data.stare.ah"
stare-2nd = "mednet.libs.segmentation.config.data.stare.vk"
......
# SPDX-FileCopyrightText: Copyright © 2024 Idiap Research Institute <contact@idiap.ch>
#
# SPDX-License-Identifier: GPL-3.0-or-later
"""CHASE-DB1 dataset for Vessel Segmentation."""
import importlib.resources
import os
from pathlib import Path
import PIL.Image
import pkg_resources
from mednet.libs.common.data.datamodule import CachingDataModule
from mednet.libs.common.data.split import JSONDatabaseSplit
from mednet.libs.common.data.typing import DatabaseSplit, Sample
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 Chase-db1 dataset."""
datadir: str
"""This variable contains the base directory where the database raw data is
stored."""
def __init__(self):
self.datadir = load_rc().get(
CONFIGURATION_KEY_DATADIR, os.path.realpath(os.curdir)
)
self._pkg_path = pkg_resources.resource_filename(__name__, "masks")
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 = PIL.Image.open(Path(self.datadir) / str(sample[0])).convert(
mode="RGB"
)
tensor = tv_tensors.Image(to_tensor(image))
target = tv_tensors.Image(
to_tensor(
PIL.Image.open(Path(self.datadir) / str(sample[1])).convert(
mode="1", dither=None
)
)
)
mask = tv_tensors.Mask(
to_tensor(
PIL.Image.open(Path(self._pkg_path) / str(sample[2])).convert(
mode="1", dither=None
)
)
)
return tensor, dict(target=target, mask=mask, name=sample[0]) # type: ignore[arg-type]
def make_split(basename: str) -> DatabaseSplit:
"""Return a database split for the Chase-db1 database.
Parameters
----------
basename
Name of the .json file containing the split to load.
Returns
-------
An instance of DatabaseSplit.
"""
return JSONDatabaseSplit(
importlib.resources.files(__name__.rsplit(".", 1)[0]).joinpath(basename)
)
class DataModule(CachingDataModule):
"""CHASE-DB1 dataset for Vessel Segmentation.
The CHASE_DB1 is a retinal vessel reference dataset acquired from multiethnic
school children. This database is a part of the Child Heart and Health Study in
England (CHASE), a cardiovascular health survey in 200 primary schools in
London, Birmingham, and Leicester. The ocular imaging was carried out in
46 schools and demonstrated associations between retinal vessel tortuosity and
early risk factors for cardiovascular disease in over 1000 British primary
school children of different ethnic origin. The retinal images of both of the
eyes of each child were recorded with a hand-held Nidek NM-200-D fundus camera.
The images were captured at 30 degrees FOV camera. The dataset of images are
characterized by having nonuniform back-ground illumination, poor contrast of
blood vessels as compared with the background and wider arteriolars that have a
bright strip running down the centre known as the central vessel reflex.
* Reference: [CHASEDB1-2012]_
* Original resolution (height x width): 960 x 999
* Split reference: [CHASEDB1-2012]_
* Protocol ``first-annotator``:
* Training samples: 8 (including labels from annotator "1stHO")
* Test samples: 20 (including labels from annotator "1stHO")
* Protocol ``second-annotator``:
* Training samples: 8 (including labels from annotator "2ndHO")
* Test samples: 20 (including labels from annotator "2ndHO")
Parameters
----------
split_filename
Name of the .json file containing the split to load.
"""
def __init__(self, split_filename: str):
super().__init__(
database_split=make_split(split_filename),
raw_data_loader=SegmentationRawDataLoader(),
)
{
"train": [
[
"Image_11L.jpg",
"Image_11L_1stHO.png",
"Image_11L.png"
],
[
"Image_11R.jpg",
"Image_11R_1stHO.png",
"Image_11R.png"
],
[
"Image_12L.jpg",
"Image_12L_1stHO.png",
"Image_12L.png"
],
[
"Image_12R.jpg",
"Image_12R_1stHO.png",
"Image_12R.png"
],
[
"Image_13L.jpg",
"Image_13L_1stHO.png",
"Image_13L.png"
],
[
"Image_13R.jpg",
"Image_13R_1stHO.png",
"Image_13R.png"
],
[
"Image_14L.jpg",
"Image_14L_1stHO.png",
"Image_14L.png"
],
[
"Image_14R.jpg",
"Image_14R_1stHO.png",
"Image_14R.png"
]
],
"test": [
[
"Image_01L.jpg",
"Image_01L_1stHO.png",
"Image_01L.png"
],
[
"Image_01R.jpg",
"Image_01R_1stHO.png",
"Image_01R.png"
],
[
"Image_02L.jpg",
"Image_02L_1stHO.png",
"Image_02L.png"
],
[
"Image_02R.jpg",
"Image_02R_1stHO.png",
"Image_02R.png"
],
[
"Image_03L.jpg",
"Image_03L_1stHO.png",
"Image_03L.png"
],
[
"Image_03R.jpg",
"Image_03R_1stHO.png",
"Image_03R.png"
],
[
"Image_04L.jpg",
"Image_04L_1stHO.png",
"Image_04L.png"
],
[
"Image_04R.jpg",
"Image_04R_1stHO.png",
"Image_04R.png"
],
[
"Image_05L.jpg",
"Image_05L_1stHO.png",
"Image_05L.png"
],
[
"Image_05R.jpg",
"Image_05R_1stHO.png",
"Image_05R.png"
],
[
"Image_06L.jpg",
"Image_06L_1stHO.png",
"Image_06L.png"
],
[
"Image_06R.jpg",
"Image_06R_1stHO.png",
"Image_06R.png"
],
[
"Image_07L.jpg",
"Image_07L_1stHO.png",
"Image_07L.png"
],
[
"Image_07R.jpg",
"Image_07R_1stHO.png",
"Image_07R.png"
],
[
"Image_08L.jpg",
"Image_08L_1stHO.png",
"Image_08L.png"
],
[
"Image_08R.jpg",
"Image_08R_1stHO.png",
"Image_08R.png"
],
[
"Image_09L.jpg",
"Image_09L_1stHO.png",
"Image_09L.png"
],
[
"Image_09R.jpg",
"Image_09R_1stHO.png",
"Image_09R.png"
],
[
"Image_10L.jpg",
"Image_10L_1stHO.png",
"Image_10L.png"
],
[
"Image_10R.jpg",
"Image_10R_1stHO.png",
"Image_10R.png"
]
]
}
# SPDX-FileCopyrightText: Copyright © 2024 Idiap Research Institute <contact@idiap.ch>
#
# SPDX-License-Identifier: GPL-3.0-or-later
"""CHASE-DB1 dataset for Vessel Segmentation."""
from mednet.libs.segmentation.config.data.chasedb1.datamodule import DataModule
datamodule = DataModule("first-annotator.json")
src/mednet/libs/segmentation/config/data/chasedb1/masks/Image_01L.png

1.91 KiB

src/mednet/libs/segmentation/config/data/chasedb1/masks/Image_01R.png

1.89 KiB

src/mednet/libs/segmentation/config/data/chasedb1/masks/Image_02L.png

1.9 KiB

src/mednet/libs/segmentation/config/data/chasedb1/masks/Image_02R.png

1.88 KiB

src/mednet/libs/segmentation/config/data/chasedb1/masks/Image_03L.png

1.89 KiB

src/mednet/libs/segmentation/config/data/chasedb1/masks/Image_03R.png

1.91 KiB

src/mednet/libs/segmentation/config/data/chasedb1/masks/Image_04L.png

1.88 KiB

src/mednet/libs/segmentation/config/data/chasedb1/masks/Image_04R.png

1.89 KiB

src/mednet/libs/segmentation/config/data/chasedb1/masks/Image_05L.png

1.87 KiB

src/mednet/libs/segmentation/config/data/chasedb1/masks/Image_05R.png

1.91 KiB

src/mednet/libs/segmentation/config/data/chasedb1/masks/Image_06L.png

1.87 KiB

src/mednet/libs/segmentation/config/data/chasedb1/masks/Image_06R.png

1.87 KiB

src/mednet/libs/segmentation/config/data/chasedb1/masks/Image_07L.png

1.88 KiB

src/mednet/libs/segmentation/config/data/chasedb1/masks/Image_07R.png

1.88 KiB

src/mednet/libs/segmentation/config/data/chasedb1/masks/Image_08L.png

1.88 KiB

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