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"""DRIONS-DB (training set) for Optic Disc Segmentation 

5 

6The dataset originates from data collected from 55 patients with glaucoma 

7(23.1%) and eye hypertension (76.9%), and random selected from an eye fundus 

8image base belonging to the Ophthalmology Service at Miguel Servet Hospital, 

9Saragossa (Spain). It contains 110 eye fundus images with a resolution of 600 

10x 400. Two sets of ground-truth optic disc annotations are available. The first 

11set is commonly used for training and testing. The second set acts as a "human" 

12baseline. 

13 

14* Reference: [DRIONSDB-2008]_ 

15* Original resolution (height x width): 400 x 600 

16* Configuration resolution: 416 x 608 (after padding) 

17* Split reference: [MANINIS-2016]_ 

18* Protocols ``expert1`` (baseline) and ``expert2`` (human comparison): 

19 

20 * Training samples: 60 

21 * Test samples: 50 

22""" 

23 

24import csv 

25import os 

26 

27import PIL.Image 

28import PIL.ImageDraw 

29import pkg_resources 

30 

31import bob.extension 

32 

33from ..dataset import JSONDataset 

34from ..loader import load_pil_1, load_pil_rgb, make_delayed 

35 

36_protocols = [ 

37 pkg_resources.resource_filename(__name__, "expert1.json"), 

38 pkg_resources.resource_filename(__name__, "expert2.json"), 

39] 

40 

41_root_path = bob.extension.rc.get( 

42 "bob.ip.binseg.drionsdb.datadir", os.path.realpath(os.curdir) 

43) 

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

45 

46 

47def _txt_to_pil_1(fname, size): 

48 """Converts DRIONS-DB annotations to image format""" 

49 with open(fname, "r") as f: 

50 rows = csv.reader(f, delimiter=",", quoting=csv.QUOTE_NONNUMERIC) 

51 data = list(map(tuple, rows)) 

52 

53 retval = PIL.Image.new("1", size) 

54 draw = PIL.ImageDraw.ImageDraw(retval) 

55 draw.polygon(data, fill="white") 

56 del draw 

57 return retval 

58 

59 

60def _pad_right(img): 

61 """Pads image on the right by one pixel, respects mode""" 

62 retval = PIL.Image.new(img.mode, (img.size[0] + 1, img.size[1]), "black") 

63 retval.paste(img, (0, 0) + img.size) # top-left pasting 

64 return retval 

65 

66 

67def _raw_data_loader(sample): 

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

69 label = _txt_to_pil_1(os.path.join(_root_path, sample["label"]), data.size) 

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

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

72 

73 

74def _sample_101_loader(sample): 

75 # pads the image on the right side to account for a difference in 

76 # resolution to other images in the dataset 

77 retval = _raw_data_loader(sample) 

78 retval["data"] = _pad_right(retval["data"]) 

79 retval["label"] = _pad_right(retval["label"]) 

80 retval["mask"] = _pad_right(retval["mask"]) 

81 return retval 

82 

83 

84def _loader(context, sample): 

85 if sample["data"].endswith("_101.jpg"): 

86 return make_delayed(sample, _sample_101_loader) 

87 return make_delayed(sample, _raw_data_loader) 

88 

89 

90dataset = JSONDataset( 

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

92) 

93"""DRIONSDB dataset object"""