File size: 6,334 Bytes
b004d6f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
import numpy as np 
import imageio 
import json 
import torch 
import sys 
import os
import configargparse
import ast
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from loaders.utils import Rays
from utils import str2bool, load_args

def calc_psnr(img1, img2):
    # Calculate the mean squared error
    mse = np.mean((img1 - img2) ** 2)
    # Calculate the maximum possible pixel value (for data scaled between 0 and 1)
    max_pixel = 1.0
    # Calculate the PSNR
    psnr_value = 20 * np.log10(max_pixel / np.sqrt(mse))
    return psnr_value

def get_rays(img_shape, c2w, K, device):
    OPENGL_CAMERA = True
    x, y = torch.meshgrid(
                torch.arange(img_shape, device=device),
                torch.arange(img_shape, device=device),
                indexing="xy",
    )
    x = x.flatten()
    y = y.flatten()
    
    c2w = c2w.repeat(img_shape**2, 1, 1)
    camera_dirs = torch.nn.functional.pad(
            torch.stack(
                [
                    (x - K[0, 2] + 0.5) / K[0, 0],
                    (y - K[1, 2] + 0.5)
                    / K[1, 1]
                    * (-1.0 if OPENGL_CAMERA else 1.0),
                ],
                dim=-1,
            ),
            (0, 1),
            value=(-1.0 if OPENGL_CAMERA else 1.0),
        )  # [num_rays, 3]

        # [n_cams, height, width, 3]
    directions = (camera_dirs[:, None, :] * c2w[:, :3, :3]).sum(dim=-1)
    origins = torch.broadcast_to(c2w[:, :3, -1], directions.shape)
    viewdirs = directions / torch.linalg.norm(
        directions, dim=-1, keepdims=True
    )
    origins = torch.reshape(origins, (img_shape, img_shape, 3))
    viewdirs = torch.reshape(viewdirs, (img_shape, img_shape, 3))

    
    rays = Rays(origins=origins, viewdirs=viewdirs)

    return rays 


def read_json(json_path):
    f = open(json_path)
    positions = json.load(f)
    f.close()
    return positions

def generate_video(images, output_path, fps):
    # Determine the width and height of the images
    writer = imageio.get_writer(output_path, fps=fps)
    for image in images:
        writer.append_data(image)
    writer.close()

def calc_iou(rgb, gt_tran):
    intersection = np.minimum(rgb, gt_tran)
    union = np.maximum(rgb, gt_tran)
    iou = np.sum(intersection) / np.sum(union)
    return iou

def load_eval_args():
    parser = configargparse.ArgumentParser()
    parser.add('-tc', '--test_config', 
        is_config_file=True, 
        default="./configs/test/captured/cinema_quantitative.ini", 
        help='Path to config file.'
    )
    parser.add_argument(
        "--scene",
        type=str,
        default="cinema",
        # choices=[
        #     # nerf transient
        #     "lego",
        #     "chair",
        #     "drums",
        #     "ficus",
        #     "hotdog",
        #     "bench",
        #     "boar",
        #     "benches"
        # ],
        help="scene to evaluate the models on",
    )
    parser.add_argument(
        "--rep_number",
        type=int,
        default=30,
    )
    parser.add_argument(
        "--step",
        type=int,
        default=290000,
    )
    parser.add_argument(
        "--split",
        type=str,
        default="test",
    )
    parser.add_argument(
        "--test_folder_path",
        type=str,
        default="test2",
    )
    parser.add_argument(
        "--checkpoint_dir",
        type=str,
        default="/scratch/ondemand28/anagh/tnerf_release/multiview_transient/results/cinema_two_views_04-18_02:10:32",
    )
    parser.add_argument(
        "--data_folder_path",
        type=str,
        default="./data",
    )
    parser.add_argument(
        "--irf_path",
        type=str,
        default="",
        help="Path to IRF file (.csv/.npy/.mat/.pt). If empty, fallback to --pulse_path.",
    )
    parser.add_argument(
        "--irf_column",
        type=str,
        default="irf",
        help="CSV column name for IRF values.",
    )
    parser.add_argument(
        "--irf_half_window",
        type=int,
        default=50,
        help="Half window around IRF peak. Set <=0 to disable cropping.",
    )
    parser.add_argument(
        "--no_irf_reverse",
        action="store_true",
        help="Disable reverse before Conv1d kernel creation.",
    )
    parser.add_argument(
        "--measurement_root",
        type=str,
        default="",
        help="Optional measurement root for captured-ours loader.",
    )
    parser.add_argument(
        "--data_exts",
        type=str,
        default=".npz,.txt,.pt,.h5,.hdf5",
        help="Comma-separated measurement extension lookup order.",
    )
    parser.add_argument(
        "--bin_width_s_loader",
        type=float,
        default=None,
        help="Optional bin width in seconds for shift resampling.",
    )
    parser.add_argument(
        "--img_height_test",
        type=int,
        default=None,
        help="Test image height. If empty, use --img_shape_test.",
    )
    parser.add_argument(
        "--img_width_test",
        type=int,
        default=None,
        help="Test image width. If empty, use --img_shape_test.",
    )
    parser.add_argument(
        "--invalid_mask_path",
        type=str,
        default="",
        help="Optional offset map path for valid-pixel mask.",
    )
    parser.add_argument(
        "--invalid_mask_invalid_gt",
        type=float,
        default=10.0,
        help="Offset threshold: pixels with offset > threshold are invalid.",
    )
    parser.add_argument(
        "--meas_peak_min",
        type=float,
        default=100.0,
        help=(
            "Minimum raw histogram peak per pixel to keep it in evaluation metrics. "
            "<=0 disables this mask."
        ),
    )
    parser.add_argument(
        "--scale_int",
        type=float,
        default=1.0,
        help="Fixed scale for intensity normalisation (replaces per-image dynamic max).",
    )
    args = load_args(eval=True, parser=parser)
    return args

num2words = {1: 'one', 2: 'two', 3: 'three', 4: 'four', 5: 'five', 
             6: 'six', 7: 'seven', 8: 'eight', 9: 'nine', 10: 'ten', 
             11: 'eleven', 12: 'twelve', 13: 'thirteen', 14: 'fourteen', 
             15: 'fifteen', 16: 'sixteen', 17: 'seventeen', 18: 'eighteen', 19: 'nineteen'}

if __name__=="__main__":
    pass