File size: 3,276 Bytes
c8738fd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import os
import json
import argparse


def main():
    parser = argparse.ArgumentParser(
        description="Generate metadata.jsonl for DayRainDrop dataset"
    )
    parser.add_argument(
        "--root_dir", default="DayRainDrop_Train", help="Root directory of the dataset"
    )
    parser.add_argument(
        "--blur_dir_name", default="Blur", help="Name of the blur directory"
    )
    parser.add_argument(
        "--clear_dir_name", default="Clear", help="Name of the clear directory"
    )
    parser.add_argument(
        "--drop_dir_name", default="Drop", help="Name of the drop directory"
    )
    parser.add_argument(
        "--output_path",
        default="output/metadata.jsonl",
        help="Output path for metadata.jsonl",
    )

    args = parser.parse_args()

    root_dir = args.root_dir
    blur_dir = os.path.join(root_dir, args.blur_dir_name)
    clear_dir = os.path.join(root_dir, args.clear_dir_name)
    drop_dir = os.path.join(root_dir, args.drop_dir_name)
    output_path = args.output_path

    # Ensure output directory exists
    os.makedirs(os.path.dirname(output_path), exist_ok=True)

    # Get absolute path of output directory for relative paths
    output_dir = os.path.dirname(os.path.abspath(output_path))

    with open(output_path, "w") as f:
        # Iterate over subdirectories in drop_dir
        for subdir in sorted(os.listdir(drop_dir)):
            blur_sub = os.path.join(blur_dir, subdir)
            clear_sub = os.path.join(clear_dir, subdir)
            drop_sub = os.path.join(drop_dir, subdir)

            if not os.path.isdir(drop_sub):
                continue

            # Get PNG files in drop_sub
            drop_files = sorted(
                [f for f in os.listdir(drop_sub) if f.lower().endswith(".png")]
            )

            # Use drop_files as the base
            for fname in drop_files:
                drop_path = os.path.join(drop_sub, fname)
                blur_path = (
                    os.path.join(blur_sub, fname)
                    if os.path.exists(os.path.join(blur_sub, fname))
                    else None
                )
                clear_path = (
                    os.path.join(clear_sub, fname)
                    if os.path.exists(os.path.join(clear_sub, fname))
                    else None
                )

                # Compute relative paths from output directory
                rel_drop = os.path.relpath(drop_path, output_dir)
                rel_blur = os.path.relpath(blur_path, output_dir) if blur_path else None
                rel_clear = (
                    os.path.relpath(clear_path, output_dir) if clear_path else None
                )

                entry = {}
                if rel_drop:
                    entry["drop_file_name"] = rel_drop
                else:
                    entry["drop_file_name"] = None
                if rel_blur:
                    entry["blur_file_name"] = rel_blur
                else:
                    entry["blur_file_name"] = None
                if rel_clear:
                    entry["clear_file_name"] = rel_clear
                else:
                    entry["clear_file_name"] = None
                f.write(json.dumps(entry) + "\n")


if __name__ == "__main__":
    main()