Skip to content

Commit 4f28212

Browse files
authored
Merge pull request #3 from barnjamin/master
adding configurable depth bits
2 parents 0c00f02 + 9a71bc9 commit 4f28212

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

run.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def run(input_path, output_path, model_path):
5555
filename = os.path.join(
5656
output_path, os.path.splitext(os.path.basename(img_name))[0]
5757
)
58-
utils.write_depth(filename, depth)
58+
utils.write_depth(filename, depth, bits=2)
5959

6060
print("finished")
6161

utils.py

+8-4
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,7 @@ def resize_depth(depth, width, height):
163163

164164
return depth_resized
165165

166-
167-
def write_depth(path, depth):
166+
def write_depth(path, depth, bits=1):
168167
"""Write depth map to pfm and png file.
169168
170169
Args:
@@ -176,11 +175,16 @@ def write_depth(path, depth):
176175
depth_min = depth.min()
177176
depth_max = depth.max()
178177

178+
max_val = (2**(8*bits))-1
179+
179180
if depth_max - depth_min > np.finfo("float").eps:
180-
out = 255 * (depth - depth_min) / (depth_max - depth_min)
181+
out = max_val * (depth - depth_min) / (depth_max - depth_min)
181182
else:
182183
out = 0
183184

184-
cv2.imwrite(path + ".png", out.astype("uint8"))
185+
if bits == 1:
186+
cv2.imwrite(path + ".png", out.astype("uint8"))
187+
elif bits == 2:
188+
cv2.imwrite(path + ".png", out.astype("uint16"))
185189

186190
return

0 commit comments

Comments
 (0)