-
Notifications
You must be signed in to change notification settings - Fork 21
/
add_noise_interiornet.py
61 lines (58 loc) · 2.66 KB
/
add_noise_interiornet.py
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
import torch
import cv2
import os
import sys
import argparse
import numpy
from shutil import copyfile
from importers import *
from exporters import *
from evaluation import noise
def parse_arguments(args):
usage_text = (
"Synthetic Noise Addition to InteriorNet samples."
)
parser = argparse.ArgumentParser(description=usage_text)
parser.add_argument("--interiornet_path", type=str,
default="..\\InteriorNet\\Scenes",
help="Path to the Scenes InteriorNet folder containing the files."
)
parser.add_argument("--output_path", type=str,
default="..\\InteriorNet\\noisy",
help="Path to the output folder where the resulting files will be saved."
)
parser.add_argument("--sigma_depth", type=float, default=0.56,
help = "Depth standard deviation parameter for disparity noise."
)
parser.add_argument("--sigma_space", type=float, default=0.9,
help = "Space standard deviation parameter for disparity noise."
)
parser.add_argument("--depth_fraction", type=float, default=0.6,
help = "Depth fraction parameter for ToF noise."
)
parser.add_argument("--copy_original", required=False, default=True,
action="store_true", help="Save original depth maps as well (prefixed with +gt)."
)
return parser.parse_known_args(args)
if __name__ == "__main__":
args, unknown = parse_arguments(sys.argv)
for scene_name in os.listdir(args.interiornet_path):
scene_folder = os.path.join(args.interiornet_path, scene_name)
depth_data_folder = os.path.join(scene_folder, "depth0", "data")
for depth_name in os.listdir(depth_data_folder):
depth_filename = os.path.join(depth_data_folder, depth_name)
depth = load_depth(depth_filename)
noisy_filename = scene_name + "_noisy_" + depth_name
algorithm_selector = torch.rand(1).float() < 0.5
if algorithm_selector:
sigma_space = args.sigma_space * (1.0 + torch.rand(1).float())
sigma_depth = args.sigma_depth * (1.0 + torch.rand(1).float())
noisy, _ = noise.disparity_noise(depth, sigma_depth=sigma_depth,\
sigma_space=sigma_space)
else:
depth_fraction = args.depth_fraction * (1.0 + torch.rand(1).float())
noisy = noise.tof_noise(depth, sigma_fraction=depth_fraction)
output_filename = os.path.join(args.output_path, noisy_filename)
save_depth(output_filename, noisy, scale=1000.0)
if args.copy_original:
copyfile(depth_filename, output_filename.replace(".png", "+gt.png"))