File size: 4,057 Bytes
b32aa52
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
bdc1b09
b32aa52
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# -*- encoding: utf-8 -*-

"""
@File    :   FE-Wireframe.py
@Time    :   2025/08/31 23:00:00
@Author  :   lh9171338
@Version :   1.0
@Contact :   2909171338@qq.com
"""

import os
import numpy as np
import json
import datasets
from datasets import Features, Image, Sequence, Value


_CITATION = """\
@ARTICLE{10323537,
  author={Yu, Huai and Li, Hao and Yang, Wen and Yu, Lei and Xia, Gui-Song},
  journal={IEEE Transactions on Pattern Analysis and Machine Intelligence},
  title={Detecting Line Segments in Motion-Blurred Images With Events},
  year={2023},
  pages={1-16},
  doi={10.1109/TPAMI.2023.3334877}
}
"""
_DESCRIPTION = """\
This new dataset is designed for motion-blurred image line segment detection with events.
"""
_HOMEPAGE = ""
_LICENSE = "mit"


class FEBlurframe(datasets.GeneratorBasedBuilder):
    """FE-Blurframe Dataset"""

    VERSION = datasets.Version("1.1.0")

    def _info(self):
        """infos"""
        features = Features(
            {
                "blur_image": Image(),
                "start_image": Image(),
                "end_image": Image(),
                "events": {
                    "image_size": Sequence(Value("int32")),
                    "x": Sequence(Value("int16")),
                    "y": Sequence(Value("int16")),
                    "t": Sequence(Value("int32")),
                    "p": Sequence(Value("bool")),
                },
                "H": Sequence(Sequence(Value("float32"))),  # shape [3, 3]
                "image_size": Sequence(Value("int32")),  # shape [2]
                "junc": Sequence(Sequence(Value("float32"))),  # shape [M, 2]
                "flow": Sequence(Sequence(Value("float32"))),  # shape [M, 2]
                "lines": Sequence(Sequence(Value("float32"))),  # shape [N, 4]
                "edges_positive": Sequence(Sequence(Value("float32"))),  # shape [Np, 2]
            }
        )
        return datasets.DatasetInfo(
            description=_DESCRIPTION,
            features=features,
            homepage=_HOMEPAGE,
            license=_LICENSE,
            citation=_CITATION,
        )

    def _split_generators(self, dl_manager):
        """split generators"""
        data_files = {
            "train": "train.jsonl",
            "test": "test.jsonl",
            "events_raw": "events_raw.zip",
            "images-blur": "images-blur.zip",
            "images-start": "images-start.zip",
            "images-end": "images-end.zip",
        }
        data_files = dl_manager.download_and_extract(data_files)
        print(f"data_files: {data_files}")
        return [
            datasets.SplitGenerator(
                name=datasets.Split.TRAIN,
                gen_kwargs={
                    "filepath": data_files["train"],
                    "data_files": data_files,
                },
            ),
            datasets.SplitGenerator(
                name=datasets.Split.TEST,
                gen_kwargs={
                    "filepath": data_files["test"],
                    "data_files": data_files,
                },
            ),
        ]

    def _generate_examples(self, filepath, data_files):
        """generate examples"""
        with open(filepath, encoding="utf-8") as f:
            lines = f.readlines()
        for idx, line in enumerate(lines):
            info = json.loads(line)
            new_info = dict()
            new_info["blur_image"] = os.path.join(data_files["images-blur"], "images-blur", info["filename"])
            new_info["start_image"] = os.path.join(data_files["images-start"], "images-start", info["filename"])
            new_info["end_image"] = os.path.join(data_files["images-end"], "images-end", info["filename"])
            events = np.load(
                os.path.join(data_files["events_raw"], "events_raw", info["filename"].replace(".png", ".npz"))
            )
            new_info["events"] = dict(**events)
            for key in ["image_size", "H", "junc", "flow", "lines", "edges_positive"]:
                new_info[key] = info[key]
            yield idx, new_info