Coverage for src/deepdraw/data/iostar/__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"""IOSTAR (training set) for Vessel and Optic-Disc Segmentation. 

6 

7The IOSTAR vessel segmentation dataset includes 30 images with a resolution of 

81024 × 1024 pixels. All the vessels in this dataset are annotated by a group of 

9experts working in the field of retinal image analysis. Additionally the 

10dataset includes annotations for the optic disc and the artery/vein ratio. 

11 

12* Reference: [IOSTAR-2016]_ 

13* Original resolution (height x width): 1024 x 1024 

14* Split reference: [MEYER-2017]_ 

15* Protocol ``vessel``: 

16 

17 * Training samples: 20 (including labels and masks) 

18 * Test samples: 10 (including labels and masks) 

19 

20* Protocol ``optic-disc``: 

21 

22 * Training samples: 20 (including labels and masks) 

23 * Test samples: 10 (including labels and masks) 

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 

33from ..utils import invert_mode1_image, subtract_mode1_images 

34 

35_protocols = [ 

36 pkg_resources.resource_filename(__name__, "vessel.json"), 

37 pkg_resources.resource_filename(__name__, "optic-disc.json"), 

38] 

39 

40_root_path = load_rc().get("datadir.iostar", os.path.realpath(os.curdir)) 

41 

42 

43def _vessel_loader(sample): 

44 return dict( 

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

46 label=load_pil_1(os.path.join(_root_path, sample["label"])), 

47 mask=load_pil_1(os.path.join(_root_path, sample["mask"])), 

48 ) 

49 

50 

51def _disc_loader(sample): 

52 # For optic-disc analysis, the label provided by IOSTAR raw data is the 

53 # "inverted" (negative) label, and does not consider the mask region, which 

54 # must be subtracted. We do this special manipulation here. 

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

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

57 mask = load_pil_1(os.path.join(_root_path, sample["mask"])) 

58 label = subtract_mode1_images( 

59 invert_mode1_image(label), invert_mode1_image(mask) 

60 ) 

61 return dict(data=data, label=label, mask=mask) 

62 

63 

64def _loader(context, sample): 

65 if context["protocol"] == "optic-disc": 

66 return make_delayed(sample, _disc_loader) 

67 elif context["protocol"] == "vessel": 

68 return make_delayed(sample, _vessel_loader) 

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

70 

71 

72dataset = JSONDataset( 

73 protocols=_protocols, 

74 fieldnames=("data", "label", "mask"), 

75 loader=_loader, 

76) 

77"""IOSTAR dataset object."""