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"""Montgomery County dataset for Lung Segmentation 

5 

6The database includes 58 cases with manifestation of tuberculosis, and 80 

7normal cases. It contains a total of 138 resolution of 4020 x 4892, or 

84892 x 4020. One set of ground-truth lung annotations is available. 

9 

10* Reference: [MC-2014]_ 

11* Original resolution (height x width): 4020 x 4892, or 4892 x 4020 

12* Configuration resolution: 512 x 512 (after rescaling) 

13* Split reference: [GAAL-2020]_ 

14* Protocol ``default``: 

15 

16 * Training samples: 96 (including labels) 

17 * Validation samples: 14 (including labels) 

18 * Test samples: 28 (including labels) 

19 

20""" 

21 

22import os 

23 

24import numpy as np 

25import pkg_resources 

26 

27from PIL import Image 

28 

29import bob.extension 

30 

31from ..dataset import JSONDataset 

32from ..loader import load_pil_1, load_pil_rgb, make_delayed 

33 

34_protocols = [ 

35 pkg_resources.resource_filename(__name__, "default.json"), 

36] 

37 

38_root_path = bob.extension.rc.get( 

39 "bob.ip.binseg.montgomery.datadir", os.path.realpath(os.curdir) 

40) 

41 

42 

43def _raw_data_loader(sample): 

44 return dict( 

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

46 label=Image.fromarray( 

47 np.ma.mask_or( 

48 np.asarray( 

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

50 ), 

51 np.asarray( 

52 load_pil_1(os.path.join(_root_path, sample["label_r"])) 

53 ), 

54 ) 

55 ), 

56 ) 

57 

58 

59def _loader(context, sample): 

60 # "context" is ignored in this case - database is homogeneous 

61 # we returned delayed samples to avoid loading all images at once 

62 return make_delayed(sample, _raw_data_loader) 

63 

64 

65dataset = JSONDataset( 

66 protocols=_protocols, 

67 fieldnames=("data", "label_l", "label_r"), 

68 loader=_loader, 

69) 

70 

71"""Montgomery County dataset object"""