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
4"""IOSTAR (training set) for Vessel and Optic-Disc Segmentation
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.
11* Reference: [IOSTAR-2016]_
12* Original resolution (height x width): 1024 x 1024
13* Split reference: [MEYER-2017]_
14* Protocol ``vessel``:
16 * Training samples: 20 (including labels and masks)
17 * Test samples: 10 (including labels and masks)
19* Protocol ``optic-disc``:
21 * Training samples: 20 (including labels and masks)
22 * Test samples: 10 (including labels and masks)
23"""
25import os
27import pkg_resources
29import bob.extension
31from ..dataset import JSONDataset
32from ..loader import load_pil_1, load_pil_rgb, make_delayed
33from ..utils import invert_mode1_image, subtract_mode1_images
35_protocols = [
36 pkg_resources.resource_filename(__name__, "vessel.json"),
37 pkg_resources.resource_filename(__name__, "optic-disc.json"),
38]
40_root_path = bob.extension.rc.get(
41 "bob.ip.binseg.iostar.datadir", os.path.realpath(os.curdir)
42)
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 )
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)
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']}")
74dataset = JSONDataset(
75 protocols=_protocols,
76 fieldnames=("data", "label", "mask"),
77 loader=_loader,
78)
79"""IOSTAR dataset object"""