Spaces:
Runtime error
Runtime error
Update app.py
Browse files
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 |
-
#
|
7 |
-
|
8 |
-
|
|
|
9 |
# Load the marker image (binary image with markers)
|
10 |
-
markers = cv2.
|
11 |
|
12 |
# Apply the watershed algorithm
|
13 |
-
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
|