Zeeshan01 commited on
Commit
c34126a
·
1 Parent(s): 531a854

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -7
app.py CHANGED
@@ -1,16 +1,18 @@
1
  import cv2
2
  import gradio as gr
 
3
 
4
  # Define a function for marker-based segmentation using the OpenCV watershed algorithm
5
  def watershed_segmentation(input_image, markers_image):
6
- # Load the input image
7
- image = cv2.imdecode(input_image, cv2.IMREAD_COLOR)
8
-
 
9
  # Load the marker image (binary image with markers)
10
- markers = cv2.imdecode(markers_image, cv2.IMREAD_GRAYSCALE)
11
 
12
  # Apply the watershed algorithm
13
- image_copy = image.copy()
14
  cv2.watershed(image_copy, markers)
15
 
16
  # Apply color mapping to the segmented regions
@@ -19,8 +21,8 @@ def watershed_segmentation(input_image, markers_image):
19
  return segmented_image
20
 
21
  # Define Gradio interfaces for the input and output
22
- input_image = gr.inputs.Image()
23
- markers_image = gr.inputs.Image()
24
  output_image = gr.outputs.Image()
25
 
26
  # Create a Gradio app
 
1
  import cv2
2
  import gradio as gr
3
+ import numpy as np
4
 
5
  # Define a function for marker-based segmentation using the OpenCV watershed algorithm
6
  def watershed_segmentation(input_image, markers_image):
7
+ # Convert input images to numpy arrays
8
+ input_image = np.array(input_image)
9
+ markers_image = np.array(markers_image)
10
+
11
  # Load the marker image (binary image with markers)
12
+ markers = cv2.cvtColor(markers_image, cv2.COLOR_BGR2GRAY)
13
 
14
  # Apply the watershed algorithm
15
+ image_copy = input_image.copy()
16
  cv2.watershed(image_copy, markers)
17
 
18
  # Apply color mapping to the segmented regions
 
21
  return segmented_image
22
 
23
  # Define Gradio interfaces for the input and output
24
+ input_image = gr.inputs.Image(type="numpy")
25
+ markers_image = gr.inputs.Image(type="numpy")
26
  output_image = gr.outputs.Image()
27
 
28
  # Create a Gradio app