umuthopeyildirim
commited on
Commit
·
2a2d2f8
1
Parent(s):
ea57a04
Refactor depth image saving and display
Browse filesThis commit refactors the code for saving and displaying depth images. It replaces the previous method of saving the predicted depth image with a new method that saves the raw depth image. Additionally, it applies a color map to the depth image for better visualization. This improves the overall functionality and user experience of the application.
app.py
CHANGED
@@ -103,10 +103,18 @@ with gr.Blocks(css=css) as demo:
|
|
103 |
pred_depths_r_list[-1], pred_depths_r_list_flipped[-1])
|
104 |
|
105 |
pred_depth = pred_depth.cpu().numpy().squeeze()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
106 |
tmp = tempfile.NamedTemporaryFile(suffix='.png', delete=False)
|
107 |
-
|
108 |
|
109 |
-
return [(original_image,
|
110 |
|
111 |
submit.click(on_submit, inputs=[input_image], outputs=[
|
112 |
depth_image_slider, raw_file])
|
|
|
103 |
pred_depths_r_list[-1], pred_depths_r_list_flipped[-1])
|
104 |
|
105 |
pred_depth = pred_depth.cpu().numpy().squeeze()
|
106 |
+
|
107 |
+
depth = (depth - depth.min()) / (depth.max() - depth.min()) * 255.0
|
108 |
+
depth = pred_depth.cpu().numpy().astype(np.uint8)
|
109 |
+
colored_depth = cv2.applyColorMap(
|
110 |
+
depth, cv2.COLORMAP_INFERNO)[:, :, ::-1]
|
111 |
+
|
112 |
+
raw_depth = Image.fromarray(
|
113 |
+
pred_depth.cpu().numpy().astype('uint16'))
|
114 |
tmp = tempfile.NamedTemporaryFile(suffix='.png', delete=False)
|
115 |
+
raw_depth.save(tmp.name)
|
116 |
|
117 |
+
return [(original_image, colored_depth), tmp.name]
|
118 |
|
119 |
submit.click(on_submit, inputs=[input_image], outputs=[
|
120 |
depth_image_slider, raw_file])
|