Gan Tu commited on
Commit
8dc8869
·
1 Parent(s): 7bf9fa9

fix mask generation

Browse files
Files changed (1) hide show
  1. app.py +6 -1
app.py CHANGED
@@ -3,7 +3,12 @@ import numpy as np
3
 
4
  def create_mask(img):
5
  alpha_channel = img["layers"][0][:, :, 3]
6
- mask = np.where(alpha_channel == 0, 0, 255)
 
 
 
 
 
7
  return mask
8
 
9
  with gr.Blocks(title="In-Paint Mask Creator") as demo:
 
3
 
4
  def create_mask(img):
5
  alpha_channel = img["layers"][0][:, :, 3]
6
+ # Create an output image with 4 channels (RGBA)
7
+ mask = np.zeros_like(img["layers"][0])
8
+ # Set RGB channels to white where alpha is not zero
9
+ mask[:, :, :3] = np.where(alpha_channel[:, :, None] == 0, 0, 255)
10
+ # Set alpha channel to 0 where original alpha is zero, else 255
11
+ mask[:, :, 3] = np.where(alpha_channel == 0, 255, 0)
12
  return mask
13
 
14
  with gr.Blocks(title="In-Paint Mask Creator") as demo: