File size: 779 Bytes
49a3c14
56f16c7
49a3c14
56f16c7
 
 
 
 
 
 
 
49a3c14
 
56f16c7
 
 
 
 
 
 
 
 
 
49a3c14
56f16c7
 
c4497cb
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import gradio as gr
import cv2

def create_mask(image):
   # Convert image to grayscale for easier segmentation
   gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)

   # Apply thresholding to create a binary mask (adjust threshold value as needed)
   _, mask = cv2.threshold(gray, 127, 255, cv2.THRESH_BINARY)

   return mask

with gr.Blocks() as demo:
   gr.Markdown(
       """
       # Image Mask Creator
       Draw on the image to create a mask.
       """
   )

   with gr.Row():
       base_image = gr.Image(tool="sketch", label="Base Image", width=512, height=512, show_label=True)
       mask_image = gr.Image(label="Mask Image", show_label=True)

   btn = gr.Button("Create Mask")
   btn.click(create_mask, inputs=base_image, outputs=mask_image)

demo.launch(debug=True)