Ashoka74 commited on
Commit
6d1d6c5
1 Parent(s): 9db138f

Update app_3.py

Browse files
Files changed (1) hide show
  1. app_3.py +3 -4
app_3.py CHANGED
@@ -1404,9 +1404,9 @@ def process_image(input_image, input_text):
1404
  alpha = np.zeros((H, W, 1), dtype=np.uint8)
1405
  alpha[~first_mask] = 128 # Set semi-transparency for background
1406
  alpha[first_mask] = 255 # Make the foreground opaque
1407
-
1408
  rgba = np.dstack((img, alpha)).astype(np.uint8)
1409
-
1410
  # get the bounding box of alpha
1411
  y, x = np.where(alpha > 0)
1412
  y0, y1 = max(y.min() - 1, 0), min(y.max() + 1, H)
@@ -1503,9 +1503,8 @@ def process_image(input_image, input_text):
1503
  alpha = np.zeros((H, W, 1), dtype=np.uint8)
1504
  alpha[~first_mask] = 128 # Set semi-transparency for background
1505
  alpha[first_mask] = 255 # Make the foreground opaque
1506
-
1507
  rgba = np.dstack((img, alpha)).astype(np.uint8)
1508
-
1509
  # get the bounding box of alpha
1510
  y, x = np.where(alpha > 0)
1511
  y0, y1 = max(y.min() - 1, 0), min(y.max() + 1, H)
 
1404
  alpha = np.zeros((H, W, 1), dtype=np.uint8)
1405
  alpha[~first_mask] = 128 # Set semi-transparency for background
1406
  alpha[first_mask] = 255 # Make the foreground opaque
1407
+ alpha = alpha.squeeze(-1) # Remove singleton dimension to become 2D
1408
  rgba = np.dstack((img, alpha)).astype(np.uint8)
1409
+
1410
  # get the bounding box of alpha
1411
  y, x = np.where(alpha > 0)
1412
  y0, y1 = max(y.min() - 1, 0), min(y.max() + 1, H)
 
1503
  alpha = np.zeros((H, W, 1), dtype=np.uint8)
1504
  alpha[~first_mask] = 128 # Set semi-transparency for background
1505
  alpha[first_mask] = 255 # Make the foreground opaque
1506
+ alpha = alpha.squeeze(-1) # Remove singleton dimension to become 2D
1507
  rgba = np.dstack((img, alpha)).astype(np.uint8)
 
1508
  # get the bounding box of alpha
1509
  y, x = np.where(alpha > 0)
1510
  y0, y1 = max(y.min() - 1, 0), min(y.max() + 1, H)