Update utils.py
Browse files
utils.py
CHANGED
@@ -1,4 +1,4 @@
|
|
1 |
-
from monai.transforms import Transform
|
2 |
import torch
|
3 |
import skimage
|
4 |
import torch
|
@@ -13,6 +13,7 @@ import base64
|
|
13 |
import numpy as np
|
14 |
from cv2 import dilate
|
15 |
from scipy.ndimage import label
|
|
|
16 |
|
17 |
def image_to_base64(image_path):
|
18 |
with open(image_path, "rb") as image_file:
|
@@ -79,9 +80,14 @@ def custom_colormap():
|
|
79 |
return cmap
|
80 |
|
81 |
def read_image(image_path):
|
|
|
|
|
|
|
|
|
|
|
82 |
try:
|
83 |
-
original_image =
|
84 |
-
original_image_np =
|
85 |
return original_image_np.squeeze()
|
86 |
|
87 |
except Exception as e:
|
|
|
1 |
+
from monai.transforms import Transform, Compose, LoadImage, EnsureChannelFirst
|
2 |
import torch
|
3 |
import skimage
|
4 |
import torch
|
|
|
13 |
import numpy as np
|
14 |
from cv2 import dilate
|
15 |
from scipy.ndimage import label
|
16 |
+
from Model_Seg import RgbaToGrayscale
|
17 |
|
18 |
def image_to_base64(image_path):
|
19 |
with open(image_path, "rb") as image_file:
|
|
|
80 |
return cmap
|
81 |
|
82 |
def read_image(image_path):
|
83 |
+
read_transforms = Compose([
|
84 |
+
LoadImage(image_only=True),
|
85 |
+
EnsureChannelFirst(),
|
86 |
+
RgbaToGrayscale(), # Convert RGBA to grayscale
|
87 |
+
])
|
88 |
try:
|
89 |
+
original_image = read_transforms(image_path)
|
90 |
+
original_image_np = original_image.numpy().astype(np.uint8)
|
91 |
return original_image_np.squeeze()
|
92 |
|
93 |
except Exception as e:
|