umuthopeyildirim commited on
Commit
e911b6f
1 Parent(s): e359066

Refactor image processing code to convert PyTorch tensor to NumPy array and apply color map

Browse files
Files changed (1) hide show
  1. app.py +10 -4
app.py CHANGED
@@ -102,16 +102,22 @@ with gr.Blocks(css=css) as demo:
102
  pred_depth = post_process_depth(
103
  pred_depths_r_list[-1], pred_depths_r_list_flipped[-1])
104
  print("== Finished processing image")
 
 
105
  pred_depth = pred_depth.cpu().numpy().squeeze()
106
- pred_outpu_depth = pred_depth.cpu().numpy().astype(np.uint8)
 
 
 
 
107
  output_image = cv2.applyColorMap(
108
- pred_outpu_depth, cv2.COLORMAP_INFERNO)[:, :, ::-1]
109
 
110
  # Continue with your file saving operations
111
  tmp = tempfile.NamedTemporaryFile(suffix='.png', delete=False)
112
- output_image.save(tmp.name)
113
 
114
- return [(original_image, original_image), tmp.name]
115
 
116
  submit.click(on_submit, inputs=[input_image], outputs=[
117
  depth_image_slider, raw_file])
 
102
  pred_depth = post_process_depth(
103
  pred_depths_r_list[-1], pred_depths_r_list_flipped[-1])
104
  print("== Finished processing image")
105
+
106
+ # Convert the PyTorch tensor to a NumPy array and squeeze
107
  pred_depth = pred_depth.cpu().numpy().squeeze()
108
+
109
+ # Convert to uint8 if necessary for the colormap
110
+ pred_output_depth = pred_depth.astype(np.uint8)
111
+
112
+ # Apply color map
113
  output_image = cv2.applyColorMap(
114
+ pred_output_depth, cv2.COLORMAP_INFERNO)[:, :, ::-1]
115
 
116
  # Continue with your file saving operations
117
  tmp = tempfile.NamedTemporaryFile(suffix='.png', delete=False)
118
+ cv2.imwrite(tmp.name, output_image)
119
 
120
+ return [(original_image, output_image), tmp.name]
121
 
122
  submit.click(on_submit, inputs=[input_image], outputs=[
123
  depth_image_slider, raw_file])