nithinm19 commited on
Commit
c25ecb0
·
verified ·
1 Parent(s): f14d347

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -2
app.py CHANGED
@@ -37,17 +37,21 @@ def segment_image(image):
37
  outputs = model(**inputs)
38
  logits = outputs.logits
39
  segmentation = torch.argmax(logits, dim=1).squeeze().cpu().numpy()
 
 
 
40
 
41
- # Create a blank mask image
42
  segmented_image = np.zeros_like(image)
43
 
44
  # Color each part with unique colors
45
  for part, color in PART_COLORS.items():
46
- mask = np.isin(segmentation, PART_LABELS[part])
47
  segmented_image[mask] = color
48
 
49
  return segmented_image
50
 
 
51
  def estimate_pose(image):
52
  # Convert image from BGR (OpenCV) to RGB
53
  image_rgb = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
 
37
  outputs = model(**inputs)
38
  logits = outputs.logits
39
  segmentation = torch.argmax(logits, dim=1).squeeze().cpu().numpy()
40
+
41
+ # Resize segmentation mask to match original image size
42
+ segmentation_resized = cv2.resize(segmentation, (image.shape[1], image.shape[0]), interpolation=cv2.INTER_NEAREST)
43
 
44
+ # Create a blank mask image with the same size as the original image
45
  segmented_image = np.zeros_like(image)
46
 
47
  # Color each part with unique colors
48
  for part, color in PART_COLORS.items():
49
+ mask = np.isin(segmentation_resized, PART_LABELS[part])
50
  segmented_image[mask] = color
51
 
52
  return segmented_image
53
 
54
+
55
  def estimate_pose(image):
56
  # Convert image from BGR (OpenCV) to RGB
57
  image_rgb = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)