Coverage for src/deepdraw/data/jsrt/__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"""Japanese Society of Radiological Technology dataset for Lung Segmentation.
7The database includes 154 nodule and 93 non-nodule images. It contains a total
8of 247 resolution of 2048 x 2048. One set of ground-truth lung annotations is
9available.
11* Reference: [JSRT-2000]_
12* Original resolution (height x width): 2048 x 2048
13* Configuration resolution: 1024 x 1024 (after rescaling)
14* Split reference: [GAAL-2020]_
15* Protocol ``default``:
17 * Training samples: 172 (including labels)
18 * Validation samples: 25 (including labels)
19 * Test samples: 50 (including labels)
20"""
22import os
24import numpy
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_raw_12bit_jsrt, make_delayed
33_protocols = [
34 pkg_resources.resource_filename(__name__, "default.json"),
35]
37_root_path = load_rc().get("datadir.jsrt", os.path.realpath(os.curdir))
40def _raw_data_loader(sample):
41 return dict(
42 data=load_pil_raw_12bit_jsrt(
43 os.path.join(_root_path, sample["data"]), 1024
44 ),
45 label=Image.fromarray(
46 numpy.ma.mask_or(
47 numpy.asarray(
48 load_pil_1(os.path.join(_root_path, sample["label_l"]))
49 ),
50 numpy.asarray(
51 load_pil_1(os.path.join(_root_path, sample["label_r"]))
52 ),
53 )
54 ),
55 )
58def _loader(context, sample):
59 # "context" is ignored in this case - database is homogeneous
60 # we returned delayed samples to avoid loading all images at once
61 return make_delayed(sample, _raw_data_loader)
64dataset = JSONDataset(
65 protocols=_protocols,
66 fieldnames=("data", "label_l", "label_r"),
67 loader=_loader,
68)
69"""Japanese Society of Radiological Technology dataset object."""