svjack commited on
Commit
b6938c7
·
verified ·
1 Parent(s): f6e691a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -8
app.py CHANGED
@@ -49,19 +49,21 @@ def process_image(img):
49
  masks.append(mask)
50
 
51
  # 生成合并后的 mask(使用对应颜色的 RGB 值)
52
- merged_mask = np.zeros((height, width, 3), dtype=np.uint8) # RGB 图像
53
  for i, mask in enumerate(masks):
54
- merged_mask[mask] = palette[i] # 使用对应颜色填充
 
55
 
56
  # 将 mask 转换为 PIL 图像(使用对应颜色的 RGB 值)
57
  mask_images = []
58
  for i, mask in enumerate(masks):
59
- mask_array = np.ones((height, width, 3), dtype=np.uint8) * 255 # 白色背景
60
- mask_array[mask] = palette[i] # 使用对应颜色填充
61
- mask_image = Image.fromarray(mask_array, mode='RGB')
 
62
  mask_images.append(mask_image)
63
 
64
- merged_mask_image = Image.fromarray(merged_mask, mode='RGB')
65
 
66
  # 保存 mask 到本地
67
  output_dir = "output_masks"
@@ -78,7 +80,7 @@ with gr.Blocks() as demo:
78
  # 添加 HTML 标题和介绍
79
  gr.Markdown("""
80
  # 🎨 **Multi-Color Mask Generator**
81
- Welcome to the **Multi-Color Mask Generator**! This tool allows you to upload an image, draw masks using different colors, and generate corresponding mask images. Each mask is saved as an RGB image, and a merged mask is also created for your convenience.
82
  """)
83
 
84
  with gr.Row():
@@ -121,7 +123,7 @@ with gr.Blocks() as demo:
121
  3. Click the **Generate Masks** button to create and save the masks.
122
  4. View the generated masks on the right side.
123
  ## 📂 **Output**
124
- - Each mask is saved as an RGB image in the `output_masks` directory.
125
  - A merged mask is also generated for your convenience.
126
  ## 🚀 **Enjoy!**
127
  """)
 
49
  masks.append(mask)
50
 
51
  # 生成合并后的 mask(使用对应颜色的 RGB 值)
52
+ merged_mask = np.zeros((height, width, 4), dtype=np.uint8) # RGBA 图像
53
  for i, mask in enumerate(masks):
54
+ merged_mask[mask, :3] = palette[i] # 使用对应颜色填充 RGB 通道
55
+ merged_mask[mask, 3] = 255 # 设置不透明度为完全不透明
56
 
57
  # 将 mask 转换为 PIL 图像(使用对应颜色的 RGB 值)
58
  mask_images = []
59
  for i, mask in enumerate(masks):
60
+ mask_array = np.zeros((height, width, 4), dtype=np.uint8) # RGBA 图像
61
+ mask_array[mask, :3] = palette[i] # 使用对应颜色填充 RGB 通道
62
+ mask_array[mask, 3] = 255 # 设置不透明度为完全不透明
63
+ mask_image = Image.fromarray(mask_array, mode='RGBA')
64
  mask_images.append(mask_image)
65
 
66
+ merged_mask_image = Image.fromarray(merged_mask, mode='RGBA')
67
 
68
  # 保存 mask 到本地
69
  output_dir = "output_masks"
 
80
  # 添加 HTML 标题和介绍
81
  gr.Markdown("""
82
  # 🎨 **Multi-Color Mask Generator**
83
+ Welcome to the **Multi-Color Mask Generator**! This tool allows you to upload an image, draw masks using different colors, and generate corresponding mask images. Each mask is saved as an RGBA image, and a merged mask is also created for your convenience.
84
  """)
85
 
86
  with gr.Row():
 
123
  3. Click the **Generate Masks** button to create and save the masks.
124
  4. View the generated masks on the right side.
125
  ## 📂 **Output**
126
+ - Each mask is saved as an RGBA image in the `output_masks` directory.
127
  - A merged mask is also generated for your convenience.
128
  ## 🚀 **Enjoy!**
129
  """)