Tinsae commited on
Commit
06f5362
1 Parent(s): bdb5e8f
Files changed (1) hide show
  1. app.py +9 -3
app.py CHANGED
@@ -16,11 +16,17 @@ def create_mask(input):
16
 
17
  input.save(input_path)
18
  bg_removed = remove(input)
 
 
 
 
 
 
19
 
20
- bg_removed = bg_removed.resize((512, 512))
21
- bg_removed.save(bg_removed_path)
22
 
23
- img2_grayscale = bg_removed.convert('L')
24
  img2_a = np.array(img2_grayscale)
25
 
26
  mask = np.array(img2_grayscale)
 
16
 
17
  input.save(input_path)
18
  bg_removed = remove(input)
19
+
20
+ width, height = bg_removed.size
21
+ max_dim = max(width, height)
22
+ square_img = Image.new('RGB', (max_dim, max_dim), (255, 255, 255))
23
+ paste_pos = ((max_dim - width) // 2, (max_dim - height) // 2)
24
+ square_img.paste(bg_removed, paste_pos)
25
 
26
+ square_img = square_img.resize((512, 512))
27
+ square_img.save(bg_removed_path)
28
 
29
+ img2_grayscale = square_img.convert('L')
30
  img2_a = np.array(img2_grayscale)
31
 
32
  mask = np.array(img2_grayscale)