(image)
| 58 | cmap = matplotlib.colormaps.get_cmap('Spectral_r') |
| 59 | |
| 60 | def on_submit(image): |
| 61 | original_image = image.copy() |
| 62 | |
| 63 | h, w = image.shape[:2] |
| 64 | |
| 65 | depth = predict_depth(image[:, :, ::-1]) |
| 66 | |
| 67 | raw_depth = Image.fromarray(depth.astype('uint16')) |
| 68 | tmp_raw_depth = tempfile.NamedTemporaryFile(suffix='.png', delete=False) |
| 69 | raw_depth.save(tmp_raw_depth.name) |
| 70 | |
| 71 | depth = (depth - depth.min()) / (depth.max() - depth.min()) * 255.0 |
| 72 | depth = depth.astype(np.uint8) |
| 73 | colored_depth = (cmap(depth)[:, :, :3] * 255).astype(np.uint8) |
| 74 | |
| 75 | gray_depth = Image.fromarray(depth) |
| 76 | tmp_gray_depth = tempfile.NamedTemporaryFile(suffix='.png', delete=False) |
| 77 | gray_depth.save(tmp_gray_depth.name) |
| 78 | |
| 79 | return [(original_image, colored_depth), tmp_gray_depth.name, tmp_raw_depth.name] |
| 80 | |
| 81 | submit.click(on_submit, inputs=[input_image], outputs=[depth_image_slider, gray_depth_file, raw_file]) |
| 82 |
nothing calls this directly
no test coverage detected