Spaces:
Sleeping
Sleeping
Samanta Das
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -1,5 +1,7 @@
|
|
1 |
import gradio as gr
|
2 |
from PIL import Image, ImageDraw
|
|
|
|
|
3 |
import sys
|
4 |
import os
|
5 |
import time
|
@@ -54,8 +56,18 @@ def analyze_image(input_image):
|
|
54 |
|
55 |
try:
|
56 |
logging.info("Performing fracture detection.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
57 |
# Perform fracture detection
|
58 |
-
detections = detector.detect_fractures(
|
59 |
|
60 |
# Mark the fracture areas on the image
|
61 |
marked_image = mark_fracture_area(input_image.copy(), detections)
|
|
|
1 |
import gradio as gr
|
2 |
from PIL import Image, ImageDraw
|
3 |
+
import numpy as np
|
4 |
+
import cv2 # Add OpenCV to handle image processing
|
5 |
import sys
|
6 |
import os
|
7 |
import time
|
|
|
56 |
|
57 |
try:
|
58 |
logging.info("Performing fracture detection.")
|
59 |
+
|
60 |
+
# Convert PIL image to NumPy array for OpenCV
|
61 |
+
img_array = np.array(input_image) # Convert PIL image to NumPy array
|
62 |
+
if len(img_array.shape) == 2: # Grayscale image
|
63 |
+
img_array = cv2.cvtColor(img_array, cv2.COLOR_GRAY2BGR)
|
64 |
+
elif img_array.shape[2] == 4: # RGBA image
|
65 |
+
img_array = cv2.cvtColor(img_array, cv2.COLOR_RGBA2BGR)
|
66 |
+
else:
|
67 |
+
img_array = cv2.cvtColor(img_array, cv2.COLOR_RGB2BGR)
|
68 |
+
|
69 |
# Perform fracture detection
|
70 |
+
detections = detector.detect_fractures(img_array, conf_threshold=0.25)
|
71 |
|
72 |
# Mark the fracture areas on the image
|
73 |
marked_image = mark_fracture_area(input_image.copy(), detections)
|