Coverage for src/deepdraw/data/montgomery/__init__.py: 94%
16 statements
« prev ^ index » next coverage.py v7.3.1, created at 2023-11-30 15:00 +0100
« 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
5"""Montgomery County dataset for Lung Segmentation.
7The database includes 58 cases with manifestation of tuberculosis, and 80
8normal cases. It contains a total of 138 resolution of 4020 x 4892, or
94892 x 4020. One set of ground-truth lung annotations is available.
11* Reference: [MC-2014]_
12* Original resolution (height x width): 4020 x 4892, or 4892 x 4020
13* Configuration resolution: 512 x 512 (after rescaling)
14* Split reference: [GAAL-2020]_
15* Protocol ``default``:
17 * Training samples: 96 (including labels)
18 * Validation samples: 14 (including labels)
19 * Test samples: 28 (including labels)
20"""
22import os
24import numpy as np
25import pkg_resources
27from PIL import Image
29from ...data.dataset import JSONDataset
30from ...utils.rc import load_rc
31from ..loader import load_pil_1, load_pil_rgb, make_delayed
33_protocols = [
34 pkg_resources.resource_filename(__name__, "default.json"),
35]
37_root_path = load_rc().get("datadir.montgomery", os.path.realpath(os.curdir))
40def _raw_data_loader(sample):
41 return dict(
42 data=load_pil_rgb(os.path.join(_root_path, sample["data"])),
43 label=Image.fromarray(
44 np.ma.mask_or(
45 np.asarray(
46 load_pil_1(os.path.join(_root_path, sample["label_l"]))
47 ),
48 np.asarray(
49 load_pil_1(os.path.join(_root_path, sample["label_r"]))
50 ),
51 )
52 ),
53 )
56def _loader(context, sample):
57 # "context" is ignored in this case - database is homogeneous
58 # we returned delayed samples to avoid loading all images at once
59 return make_delayed(sample, _raw_data_loader)
62dataset = JSONDataset(
63 protocols=_protocols,
64 fieldnames=("data", "label_l", "label_r"),
65 loader=_loader,
66)
68"""Montgomery County dataset object"""