kyleleey commited on
Commit
4496e29
1 Parent(s): 0399b2e

update image and mesh vis

Browse files
Files changed (1) hide show
  1. app.py +12 -3
app.py CHANGED
@@ -91,7 +91,12 @@ def sam_segment(predictor, input_image, *bbox_coords):
91
 
92
  out_image_bbox = out_image_bbox[y_min:y_max, x_min:x_max]
93
 
94
- return Image.fromarray(out_image_bbox, mode='RGBA')
 
 
 
 
 
95
 
96
 
97
  def expand2square(pil_img, background_color):
@@ -124,7 +129,7 @@ def preprocess(predictor, input_image, chk_group=None, segment=False):
124
  y_max = int(y_nonzero[0].max())
125
  input_image = sam_segment(predictor, input_image.convert('RGB'), x_min, y_min, x_max, y_max)
126
 
127
- input_image = expand2square(input_image, (0, 0, 0, 0))
128
  return input_image, input_image.resize((256, 256), Image.Resampling.LANCZOS)
129
 
130
 
@@ -448,7 +453,11 @@ def process_mesh(shape, name):
448
  process=False,
449
  maintain_order=True
450
  )
451
- mesh_tri.visual.vertex_colors = (mesh.v_nrm[0][..., [2,1,0]].detach().cpu().numpy() + 1.0) * 0.5 * 255.0
 
 
 
 
452
  mesh_tri.export(file_obj=output_glb)
453
 
454
  return output_glb, output_obj
 
91
 
92
  out_image_bbox = out_image_bbox[y_min:y_max, x_min:x_max]
93
 
94
+ out_image_valid = np.concatenate([
95
+ out_image_bbox[:, :, :3],
96
+ np.ones_like(out_image_bbox[:, :, 3:]) * 255
97
+ ], axis=-1)
98
+
99
+ return Image.fromarray(out_image_valid, mode='RGBA')
100
 
101
 
102
  def expand2square(pil_img, background_color):
 
129
  y_max = int(y_nonzero[0].max())
130
  input_image = sam_segment(predictor, input_image.convert('RGB'), x_min, y_min, x_max, y_max)
131
 
132
+ input_image = expand2square(input_image, (0, 0, 0, 255))
133
  return input_image, input_image.resize((256, 256), Image.Resampling.LANCZOS)
134
 
135
 
 
453
  process=False,
454
  maintain_order=True
455
  )
456
+
457
+ norm_colors = (mesh.v_nrm[0][..., [2,1,0]].detach().cpu().numpy() + 1.0) * 0.5 * 1.8 * 255.0
458
+ norm_colors = np.clip(norm_colors, 0, 255)
459
+
460
+ mesh_tri.visual.vertex_colors = norm_colors
461
  mesh_tri.export(file_obj=output_glb)
462
 
463
  return output_glb, output_obj