Coverage for src/deepdraw/data/drishtigs1/__init__.py: 72%

25 statements  

« prev     ^ index     » next       coverage.py v7.3.1, created at 2023-11-30 15:00 +0100

1# SPDX-FileCopyrightText: Copyright © 2023 Idiap Research Institute <contact@idiap.ch> 

2# 

3# SPDX-License-Identifier: GPL-3.0-or-later 

4 

5"""Drishti-GS1 for Optic Disc and Cup Segmentation. 

6 

7Drishti-GS is a dataset meant for validation of segmenting OD, cup and 

8detecting notching. The images in the Drishti-GS dataset have been collected 

9and annotated by Aravind Eye hospital, Madurai, India. This dataset is of a 

10single population as all subjects whose eye images are part of this dataset are 

11Indians. 

12 

13The dataset is divided into two: a training set and a testing set of images. 

14Training images (50) are provided with groundtruths for OD and Cup segmentation 

15and notching information. 

16 

17* Reference (including train/test split): [DRISHTIGS1-2014]_ 

18* Original resolution (height x width): varying (min: 1749 x 2045, max: 1845 x 

19 2468) 

20* Configuration resolution: 1760 x 2048 (after center cropping) 

21* Protocols ``optic-disc`` and ``optic-cup``: 

22 * Training: 50 

23 * Test: 51 

24""" 

25 

26import os 

27 

28import pkg_resources 

29 

30from ...data.dataset import JSONDataset 

31from ...utils.rc import load_rc 

32from ..loader import load_pil_1, load_pil_rgb, make_delayed 

33 

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} 

48 

49_root_path = load_rc().get("datadir.drishtigs1", os.path.realpath(os.curdir)) 

50_pkg_path = pkg_resources.resource_filename(__name__, "masks") 

51 

52 

53def _raw_data_loader_all(sample): 

54 retval = dict( 

55 data=load_pil_rgb(os.path.join(_root_path, sample["data"])), 

56 label=load_pil_rgb(os.path.join(_root_path, sample["label"])).convert( 

57 "L" 

58 ), 

59 mask=load_pil_1(os.path.join(_pkg_path, sample["mask"])), 

60 ) 

61 retval["label"] = retval["label"].point(lambda p: p > 254, mode="1") 

62 return retval 

63 

64 

65def _raw_data_loader_any(sample): 

66 retval = dict( 

67 data=load_pil_rgb(os.path.join(_root_path, sample["data"])), 

68 label=load_pil_rgb(os.path.join(_root_path, sample["label"])).convert( 

69 "L" 

70 ), 

71 mask=load_pil_1(os.path.join(_pkg_path, sample["mask"])), 

72 ) 

73 retval["label"] = retval["label"].point(lambda p: p > 0, mode="1") 

74 return retval 

75 

76 

77def _loader(context, sample): 

78 # Drishti-GS provides softmaps of multiple annotators 

79 # we threshold to get gt where all/any of the annotators overlap 

80 if context["protocol"].endswith("-all"): 

81 return make_delayed(sample, _raw_data_loader_all) 

82 elif context["protocol"].endswith("-any"): 

83 return make_delayed(sample, _raw_data_loader_any) 

84 else: 

85 raise RuntimeError(f"Unknown protocol {context['protocol']}") 

86 

87 

88dataset = JSONDataset( 

89 protocols=_protocols, fieldnames=("data", "label", "mask"), loader=_loader 

90) 

91"""Drishti-GS1 dataset object."""