Spaces:
Sleeping
Sleeping
Updated load_image to convert image to 3 channels if needed
Browse files
app.py
CHANGED
|
@@ -10,19 +10,18 @@ import matplotlib.pyplot as plt
|
|
| 10 |
from PIL import Image
|
| 11 |
import io
|
| 12 |
|
| 13 |
-
# Function to load bounding boxes from CSV
|
| 14 |
-
def load_bounding_boxes(csv_file):
|
| 15 |
-
# Assuming CSV file has columns: 'filename', 'x_min', 'y_min', 'x_max', 'y_max'
|
| 16 |
-
df = pd.read_csv(csv_file)
|
| 17 |
-
return df
|
| 18 |
-
|
| 19 |
def load_image(file_path):
|
| 20 |
if file_path.endswith(".dcm"):
|
| 21 |
ds = pydicom.dcmread(file_path)
|
| 22 |
img = ds.pixel_array
|
| 23 |
else:
|
| 24 |
-
img = np.array(Image.open(file_path)
|
| 25 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
return img, H, W
|
| 27 |
|
| 28 |
# MedSAM inference function
|
|
|
|
| 10 |
from PIL import Image
|
| 11 |
import io
|
| 12 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
def load_image(file_path):
|
| 14 |
if file_path.endswith(".dcm"):
|
| 15 |
ds = pydicom.dcmread(file_path)
|
| 16 |
img = ds.pixel_array
|
| 17 |
else:
|
| 18 |
+
img = np.array(Image.open(file_path))
|
| 19 |
+
|
| 20 |
+
# Convert grayscale to 3-channel RGB by replicating channels
|
| 21 |
+
if len(img.shape) == 2: # Grayscale image (height, width)
|
| 22 |
+
img = np.stack((img,)*3, axis=-1) # Replicate grayscale channel to get (height, width, 3)
|
| 23 |
+
|
| 24 |
+
H, W = img.shape[:2]
|
| 25 |
return img, H, W
|
| 26 |
|
| 27 |
# MedSAM inference function
|