mirror of
https://github.com/nerfstudio-project/nerfstudio.git
synced 2026-11-13 03:14:00 +08:00
last commit before SIG ASIA
This commit is contained in:
1 parent
0ab3139b19
commit
d9d7d0baa2
22 files changed
+447
-33
No files matched your search
@@ -7,7 +7,7 @@ import argparse
|
||||
import json
|
||||
|
||||
|
||||
FAST_EXPOSURE_CUTOFF = 0.2 # good for real data (0.1 for synthetic)
|
||||
FAST_EXPOSURE_CUTOFF = 0.1 # good for real data (0.1 for synthetic)
|
||||
WELL_EXPOSURE_CUTOFF = 0.98 # good for real data (0.9 for synthetic)
|
||||
|
||||
|
||||
@@ -94,8 +94,9 @@ if __name__ == "__main__":
|
||||
# fast_mask = cv2.imread(well_mask_addr.replace('/well_mask/', '/fast_mask/'))
|
||||
# fast_mask = fast_mask.astype(np.float32) / 255.0
|
||||
|
||||
final_output = weights_well * (hdr_well_image / WELL_EXPOSURE) + weights_fast * (hdr_fast_image / FAST_EXPOSURE)
|
||||
# final_output = weights_well * (hdr_well_image / WELL_EXPOSURE) + (hdr_fast_image / FAST_EXPOSURE)
|
||||
# final_output = weights_well * (hdr_well_image / WELL_EXPOSURE) + weights_fast * (hdr_fast_image / FAST_EXPOSURE)
|
||||
# final_output = final_output / (weights_well+weights_well)
|
||||
final_output = weights_well * (hdr_well_image / WELL_EXPOSURE) + (hdr_fast_image / FAST_EXPOSURE)
|
||||
# final_output = weights_well * (hdr_well_image / WELL_EXPOSURE)
|
||||
|
||||
output_addr = well_addr.replace(args.well_dir, args.out_dir)
|
||||
|
||||
Executable
+110
@@ -0,0 +1,110 @@
|
||||
import os
|
||||
import numpy as np
|
||||
import cv2
|
||||
from pathlib import Path
|
||||
from tqdm import tqdm
|
||||
import argparse
|
||||
import json
|
||||
|
||||
|
||||
FAST_EXPOSURE_CUTOFF = 0.01 # good for real data (0.1 for synthetic)
|
||||
WELL_EXPOSURE_CUTOFF = 0.98 # good for real data (0.9 for synthetic)
|
||||
|
||||
|
||||
def apply_correction(coefs, img, CORRECTION_CURVE_TYPE) -> np.ndarray:
|
||||
# check that img is in range 0-255
|
||||
assert img.dtype == np.uint8
|
||||
assert CORRECTION_CURVE_TYPE in ['gamma']
|
||||
img = ((img.astype(np.float32) / 255.0) ** np.array(coefs).T) # * 255.0
|
||||
# img = ((img.astype(np.float32) / 255.0) ** coefs[None, None, :]) * 255.0
|
||||
return img
|
||||
|
||||
def cut_weighting_function(pixels, exposures):
|
||||
weights = np.zeros(pixels.shape, dtype=np.float32)
|
||||
|
||||
if exposures == WELL_EXPOSURE:
|
||||
weights = np.clip(-20.0 * (pixels - WELL_EXPOSURE_CUTOFF) + 1, 0.0, 1.0)
|
||||
else:
|
||||
weights = np.clip(100.0 * (pixels - FAST_EXPOSURE_CUTOFF), 0.0, 1.0)
|
||||
|
||||
return weights
|
||||
|
||||
|
||||
os.environ["OPENCV_IO_ENABLE_OPENEXR"] = "1"
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument('--well_dir', type=str, default='/mnt/workspace/lantern/nerfstudio-HDR/well_at_fast/')
|
||||
parser.add_argument('--fast_dir', type=str, default='/mnt/data/nerfstudio_ds/real_data/meeting_room_openSFM/meeting_room_ns/images/')
|
||||
parser.add_argument('--out_dir', type=str, default='./output_well_at_fast/')
|
||||
parser.add_argument('--do_linearization', action='store_true')
|
||||
parser.add_argument('--experiment_location', type=str, default='/mnt/data/nerfstudio_ds/real_data/meeting_room_openSFM')
|
||||
args = parser.parse_args()
|
||||
|
||||
experiment_setup = args.experiment_location + '/capture_settings.json'
|
||||
assert os.path.exists(experiment_setup), "!!!! Cannot find the files for exposure setup. !!!"
|
||||
with open(experiment_setup) as f:
|
||||
data = json.load(f)
|
||||
WELL_EXPOSURE = 1.0
|
||||
FAST_EXPOSURE = data["right"]["shutter_speed"] / data["left"]["shutter_speed"]
|
||||
|
||||
if not os.path.exists(args.out_dir):
|
||||
os.makedirs(args.out_dir)
|
||||
|
||||
well_addr = args.well_dir
|
||||
|
||||
with open(f'linearize-ricoh-z10-wb-3500.json') as f:
|
||||
camera_data = json.load(f)
|
||||
CORRECTION_CURVE_TYPE = 'gamma'
|
||||
|
||||
well_images = []
|
||||
if args.do_linearization:
|
||||
for path in Path(well_addr).rglob('*-img.png'):
|
||||
well_images.append(path)
|
||||
else:
|
||||
for path in Path(well_addr).rglob('*.exr'):
|
||||
well_images.append(path)
|
||||
|
||||
for well_addr in tqdm(well_images):
|
||||
|
||||
well_addr = str(well_addr)
|
||||
|
||||
print("well_addr: ", well_addr)
|
||||
|
||||
hdr_well_image = cv2.imread(well_addr, cv2.IMREAD_UNCHANGED)
|
||||
fast_addr = well_addr.replace(args.well_dir, args.fast_dir)
|
||||
fast_addr = fast_addr.replace("-img.png", ".png")
|
||||
hdr_fast_image = cv2.imread(fast_addr, cv2.IMREAD_UNCHANGED)
|
||||
|
||||
|
||||
|
||||
# hdr_well_image = np.uint8(hdr_well_image * 255.0)
|
||||
# hdr_fast_image = np.uint8(hdr_fast_image * 255.0)
|
||||
|
||||
if args.do_linearization:
|
||||
hdr_well_image = apply_correction((camera_data["b"], camera_data["g"], camera_data["r"]), np.array(hdr_well_image), CORRECTION_CURVE_TYPE)
|
||||
hdr_fast_image = apply_correction((camera_data["b"], camera_data["g"], camera_data["r"]), np.array(hdr_fast_image), CORRECTION_CURVE_TYPE)
|
||||
|
||||
|
||||
# well_mask_addr = well_addr.replace('/well_expo/', '/well_mask/')
|
||||
# well_mask_addr = well_mask_addr.replace('.exr', '.png')
|
||||
# well_mask = cv2.imread(well_mask_addr)
|
||||
# well_mask = well_mask.astype(np.float32) / 255.0
|
||||
# well_mask[well_mask > 0.1] = 1.0
|
||||
|
||||
weights_well = cut_weighting_function(hdr_well_image, WELL_EXPOSURE)
|
||||
weights_fast = cut_weighting_function(hdr_fast_image, FAST_EXPOSURE)
|
||||
|
||||
# fast_mask = cv2.imread(well_mask_addr.replace('/well_mask/', '/fast_mask/'))
|
||||
# fast_mask = fast_mask.astype(np.float32) / 255.0
|
||||
|
||||
# final_output = weights_well * (hdr_well_image / WELL_EXPOSURE) + weights_fast * (hdr_fast_image / FAST_EXPOSURE)
|
||||
final_output = weights_well * (hdr_well_image / WELL_EXPOSURE) + (hdr_fast_image / FAST_EXPOSURE)
|
||||
# final_output = weights_well * (hdr_well_image / WELL_EXPOSURE)
|
||||
|
||||
output_addr = well_addr.replace(args.well_dir, args.out_dir)
|
||||
if args.do_linearization:
|
||||
output_addr = output_addr.replace('-img.png', '.exr')
|
||||
cv2.imwrite(output_addr, np.float32(final_output) )
|
||||
# import pdb; pdb.set_trace()
|
||||
Regular → Executable
File mode changed.
Regular → Executable
+3
@@ -25,6 +25,9 @@ if __name__ == "__main__":
|
||||
args = parser.parse_args()
|
||||
well_addr = args.data_dir
|
||||
|
||||
if not os.path.exists(args.out_dir):
|
||||
os.makedirs(args.out_dir)
|
||||
|
||||
with open(f'./linearize-ricoh-z10-wb-3500.json') as f:
|
||||
camera_data = json.load(f)
|
||||
CORRECTION_CURVE_TYPE = 'gamma'
|
||||
|
||||
Executable
+38
@@ -0,0 +1,38 @@
|
||||
import argparse
|
||||
import numpy as np
|
||||
import os
|
||||
from tqdm import tqdm
|
||||
from PIL import Image
|
||||
from pathlib import Path
|
||||
import PIL.ExifTags
|
||||
import json
|
||||
os.environ["OPENCV_IO_ENABLE_OPENEXR"] = "1"
|
||||
import cv2
|
||||
import warnings
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument('--data_dir', type=str, default='/Users/momo/Desktop/Pandora-HDR_NeRF/final_results/meeting_room/GT/pano/')
|
||||
parser.add_argument('--mask_dir', type=str, default='/Users/momo/Desktop/Pandora-HDR_NeRF/final_results/meeting_room/GT/mask/')
|
||||
parser.add_argument('--out_dir', type=str, default='/Users/momo/Desktop/Pandora-HDR_NeRF/final_results/meeting_room/GT/masked_pano/')
|
||||
args = parser.parse_args()
|
||||
|
||||
test_images = []
|
||||
for path in Path(args.data_dir).rglob('*.exr'):
|
||||
test_images.append(path)
|
||||
|
||||
for pano_addr in tqdm(test_images):
|
||||
img = cv2.imread(str(pano_addr), cv2.IMREAD_UNCHANGED)
|
||||
|
||||
mask_addr = str(pano_addr).replace(args.data_dir, args.mask_dir)
|
||||
mask_addr = mask_addr.replace('.exr', '.png')
|
||||
mask = cv2.imread(mask_addr, cv2.IMREAD_UNCHANGED)
|
||||
mask = np.float32(mask) / 255.
|
||||
|
||||
# import pdb; pdb.set_trace()
|
||||
masked_img = np.expand_dims(mask, axis=-1) * img
|
||||
# import pdb; pdb.set_trace()
|
||||
out_addr = str(pano_addr).replace(args.data_dir, args.out_dir)
|
||||
# import pdb; pdb.set_trace()
|
||||
cv2.imwrite(out_addr, np.float32(masked_img))
|
||||
Executable
+38
@@ -0,0 +1,38 @@
|
||||
import cv2
|
||||
import numpy as np
|
||||
import argparse
|
||||
|
||||
if __name__ == '__main__':
|
||||
parser = argparse.ArgumentParser(description='Make a GIF from input images')
|
||||
parser.add_argument("--input_Addr", type=str, help='input folder')
|
||||
# parser.add_argument("--input_pano_Addr", type=str, help='input folder')
|
||||
args = parser.parse_args()
|
||||
|
||||
images = []
|
||||
|
||||
from os import listdir
|
||||
from os.path import isfile, join
|
||||
|
||||
img_files = [join(args.input_Addr, f) for f in listdir(args.input_Addr) if isfile(join(args.input_Addr, f))]
|
||||
# pano_files = [join(args.input_pano_Addr, f) for f in listdir(args.input_pano_Addr) if isfile(join(args.input_pano_Addr, f))]
|
||||
img_files = sorted(img_files)
|
||||
|
||||
for i in range(len(img_files)):
|
||||
img_add = img_files[i]
|
||||
# pano_add = pano_files[i]
|
||||
print(img_add)
|
||||
# print(pano_add)
|
||||
img = cv2.imread(img_add)
|
||||
height, width, layers = img.shape
|
||||
size = (width, height)
|
||||
# pano = cv2.imread(pano_add)
|
||||
# small_pano = cv2.resize(pano, (0, 0), fx=0.3, fy=0.3)
|
||||
# img[0:small_pano.shape[0], 0:small_pano.shape[1]] = small_pano
|
||||
images.append(img)
|
||||
|
||||
out = cv2.VideoWriter('saussan_ldr_light.mp4', cv2.VideoWriter_fourcc(*'FMP4'), 10, size)
|
||||
# out = cv2.VideoWriter('my_apartement_render.mp4', cv2.VideoWriter_fourcc('X','V','I','D'), 15, size)
|
||||
|
||||
for i in range(len(images)):
|
||||
out.write(images[i])
|
||||
out.release()
|
||||
Regular → Executable
File mode changed.
Regular → Executable
File mode changed.
Regular → Executable
File mode changed.
Regular → Executable
+3
@@ -17,6 +17,9 @@ if __name__ == "__main__":
|
||||
parser.add_argument('--out_dir', type=str, default='/Users/momo/Desktop/Pandora-HDR_NeRF/final_results/Henry_Gagnon_red_and_blue/PanoHDR-NeRF/pano/')
|
||||
args = parser.parse_args()
|
||||
|
||||
if not os.path.exists(args.out_dir):
|
||||
os.makedirs(args.out_dir)
|
||||
|
||||
test_images = []
|
||||
for path in Path(args.data_dir).rglob('*.exr'):
|
||||
test_images.append(path)
|
||||
|
||||
@@ -15,14 +15,19 @@ if __name__ == "__main__":
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument('--data_dir', type=str, default='/Users/momo/Desktop/Pandora-HDR_NeRF/final_results/meeting_room/linearization_then_nerf/fast_compressed_mu_law/')
|
||||
parser.add_argument('--out_dir', type=str, default='//Users/momo/Desktop/Pandora-HDR_NeRF/final_results/meeting_room/linearization_then_nerf/fast_expo/')
|
||||
parser.add_argument('--is_jpg', action='store_true')
|
||||
args = parser.parse_args()
|
||||
|
||||
if not os.path.exists(args.out_dir):
|
||||
os.makedirs(args.out_dir)
|
||||
|
||||
test_images = []
|
||||
for path in Path(args.data_dir).rglob('*.exr'):
|
||||
test_images.append(path)
|
||||
if args.is_jpg:
|
||||
for path in Path(args.data_dir).rglob('*.jpg'):
|
||||
test_images.append(path)
|
||||
else:
|
||||
for path in Path(args.data_dir).rglob('*.exr'):
|
||||
test_images.append(path)
|
||||
|
||||
for pano_addr in tqdm(test_images):
|
||||
pano_addr = str(pano_addr)
|
||||
@@ -39,4 +44,7 @@ if __name__ == "__main__":
|
||||
|
||||
data = np.float32(data)
|
||||
data = cv2.cvtColor(data, cv2.COLOR_RGB2BGR)
|
||||
cv2.imwrite(out_dir, data)
|
||||
if args.is_jpg:
|
||||
cv2.imwrite(out_dir, data*255)
|
||||
else:
|
||||
cv2.imwrite(out_dir, data)
|
||||
Reference in new issue
Block a user