Created
December 22, 2020 20:08
-
-
Save dilaragokay/189406dc170b5a2d007a9d597c01df02 to your computer and use it in GitHub Desktop.
Compares ground truth normal maps and the ones predicted by FrameNet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
Compares ground truth normal maps and the ones predicted by FrameNet | |
''' | |
real_normal_maps_paths = [ | |
'chair/test/chair_0890_001.jpg', | |
'chair/test/chair_0904_009.jpg', | |
'desk/test/desk_0201_004.jpg', | |
'desk/test/desk_0203_012.jpg', | |
'dresser/test/dresser_0201_005.jpg', | |
'dresser/test/dresser_0203_011.jpg', | |
'monitor/test/monitor_0466_002.jpg', | |
'monitor/test/monitor_0469_008.jpg' | |
] | |
# read both normal maps | |
import glob | |
import cv2 | |
import numpy as np | |
pred_normal_maps = [] | |
scale = 2.0/255.0 | |
for file in sorted(glob.glob("framenet_pred/*pred.png")): | |
# also convert bump mapping to to [-1, 1] | |
pred_normal_maps.append(cv2.imread(file) * scale - 1) | |
real_normal_maps = [] | |
masks = [] | |
for path in real_normal_maps_paths: | |
file = 'ModelNet40_SurfLinear/' + path | |
orig_img = cv2.imread(file) | |
# only consider pixels that correspond to an object | |
resized = cv2.resize(orig_img, (320,240)) | |
mask = np.any(resized < [250, 250, 250], axis=-1) | |
# only consider pixels that correspond to an object | |
masks.append(mask) | |
# linear mapping from [0,255] to [-1,1] | |
real_normal_maps.append(resized * scale - 1) | |
# compare directions | |
for i in range(len(pred_normal_maps)): | |
result = [] | |
for r in range(len(pred_normal_maps[i])): | |
for c in range(len(pred_normal_maps[i][0])): | |
dot_product = np.dot(pred_normal_maps[i][r][c], real_normal_maps[i][r][c]) | |
dot_product = np.clip(dot_product, -1, 1) | |
angle = np.arccos(dot_product) * masks[i][r][c] / np.pi * 180 | |
result.append(angle) | |
print(np.mean(result)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment