Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1#!/usr/bin/env python
2# coding=utf-8
4"""Drishti-GS1 for Optic Disc and Cup Segmentation
6Drishti-GS is a dataset meant for validation of segmenting OD, cup and
7detecting notching. The images in the Drishti-GS dataset have been collected
8and annotated by Aravind Eye hospital, Madurai, India. This dataset is of a
9single population as all subjects whose eye images are part of this dataset are
10Indians.
12The dataset is divided into two: a training set and a testing set of images.
13Training images (50) are provided with groundtruths for OD and Cup segmentation
14and notching information.
16* Reference (including train/test split): [DRISHTIGS1-2014]_
17* Original resolution (height x width): varying (min: 1749 x 2045, max: 1845 x
18 2468)
19* Configuration resolution: 1760 x 2048 (after center cropping)
20* Protocols ``optic-disc`` and ``optic-cup``:
21 * Training: 50
22 * Test: 51
23"""
25import os
27import pkg_resources
29import bob.extension
31from ..dataset import JSONDataset
32from ..loader import load_pil_1, load_pil_rgb, make_delayed
34_protocols = {
35 "optic-disc-all": pkg_resources.resource_filename(
36 __name__, "optic-disc.json"
37 ),
38 "optic-cup-all": pkg_resources.resource_filename(
39 __name__, "optic-cup.json"
40 ),
41 "optic-disc-any": pkg_resources.resource_filename(
42 __name__, "optic-disc.json"
43 ),
44 "optic-cup-any": pkg_resources.resource_filename(
45 __name__, "optic-cup.json"
46 ),
47}
49_root_path = bob.extension.rc.get(
50 "bob.ip.binseg.drishtigs1.datadir", os.path.realpath(os.curdir)
51)
52_pkg_path = pkg_resources.resource_filename(__name__, "masks")
55def _raw_data_loader_all(sample):
56 retval = dict(
57 data=load_pil_rgb(os.path.join(_root_path, sample["data"])),
58 label=load_pil_rgb(os.path.join(_root_path, sample["label"])).convert(
59 "L"
60 ),
61 mask=load_pil_1(os.path.join(_pkg_path, sample["mask"])),
62 )
63 retval["label"] = retval["label"].point(lambda p: p > 254, mode="1")
64 return retval
67def _raw_data_loader_any(sample):
68 retval = dict(
69 data=load_pil_rgb(os.path.join(_root_path, sample["data"])),
70 label=load_pil_rgb(os.path.join(_root_path, sample["label"])).convert(
71 "L"
72 ),
73 mask=load_pil_1(os.path.join(_pkg_path, sample["mask"])),
74 )
75 retval["label"] = retval["label"].point(lambda p: p > 0, mode="1")
76 return retval
79def _loader(context, sample):
80 # Drishti-GS provides softmaps of multiple annotators
81 # we threshold to get gt where all/any of the annotators overlap
82 if context["protocol"].endswith("-all"):
83 return make_delayed(sample, _raw_data_loader_all)
84 elif context["protocol"].endswith("-any"):
85 return make_delayed(sample, _raw_data_loader_any)
86 else:
87 raise RuntimeError(f"Unknown protocol {context['protocol']}")
90dataset = JSONDataset(
91 protocols=_protocols, fieldnames=("data", "label", "mask"), loader=_loader
92)
93"""Drishti-GS1 dataset object"""