Hide keyboard shortcuts

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 

3 

4"""IOSTAR (training set) for Vessel and Optic-Disc Segmentation 

5 

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

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

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

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

10 

11* Reference: [IOSTAR-2016]_ 

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

13* Split reference: [MEYER-2017]_ 

14* Protocol ``vessel``: 

15 

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

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

18 

19* Protocol ``optic-disc``: 

20 

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

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

23""" 

24 

25import os 

26 

27import pkg_resources 

28 

29import bob.extension 

30 

31from ..dataset import JSONDataset 

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 = bob.extension.rc.get( 

41 "bob.ip.binseg.iostar.datadir", os.path.realpath(os.curdir) 

42) 

43 

44 

45def _vessel_loader(sample): 

46 return dict( 

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

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

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

50 ) 

51 

52 

53def _disc_loader(sample): 

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

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

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

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

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

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

60 label = subtract_mode1_images( 

61 invert_mode1_image(label), invert_mode1_image(mask) 

62 ) 

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

64 

65 

66def _loader(context, sample): 

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

68 return make_delayed(sample, _disc_loader) 

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

70 return make_delayed(sample, _vessel_loader) 

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

72 

73 

74dataset = JSONDataset( 

75 protocols=_protocols, 

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

77 loader=_loader, 

78) 

79"""IOSTAR dataset object"""