Tyler Ng commited on
Commit
a308b42
·
verified ·
1 Parent(s): fa6743f

Update app.py

Browse files

fix transparent background

Files changed (1) hide show
  1. app.py +13 -2
app.py CHANGED
@@ -24,8 +24,19 @@ def process_image(input_image, output_type):
24
  return None
25
 
26
  if output_type == "Transparent Background (RGBA)":
27
- # Returns the masked image with transparent background
28
- output = remover.process(input_image, type='rgba')
 
 
 
 
 
 
 
 
 
 
 
29
 
30
  elif output_type == "Green Background":
31
  # Returns the masked image with green screen background
 
24
  return None
25
 
26
  if output_type == "Transparent Background (RGBA)":
27
+ # Get the mask first
28
+ mask = remover.process(input_image, type='map')
29
+
30
+ # Convert mask to proper format
31
+ if isinstance(mask, Image.Image):
32
+ mask = mask.convert('L')
33
+ else:
34
+ mask = Image.fromarray((mask * 255).astype(np.uint8), mode='L')
35
+
36
+ # Convert original image to RGBA and apply mask as alpha channel
37
+ img_rgba = input_image.convert('RGBA')
38
+ img_rgba.putalpha(mask)
39
+ output = img_rgba
40
 
41
  elif output_type == "Green Background":
42
  # Returns the masked image with green screen background