FJDorfner commited on
Commit
767f684
1 Parent(s): 1e965fe

Upload 3 files

Browse files
Files changed (2) hide show
  1. Model_Seg.py +1 -6
  2. utils.py +9 -3
Model_Seg.py CHANGED
@@ -72,7 +72,6 @@ post_transforms = Compose([
72
 
73
 
74
  def load_and_segment_image(input_image_path, device):
75
-
76
  image_tensor = pre_transforms(input_image_path)
77
  image_tensor = image_tensor.unsqueeze(0).to(device)
78
 
@@ -84,11 +83,7 @@ def load_and_segment_image(input_image_path, device):
84
 
85
  outputs = outputs.squeeze(0)
86
 
87
- processed_outputs = post_transforms(outputs)
88
-
89
- # rotate
90
- rotate = Rotate90(spatial_axes=(0, 1), k=3)
91
- processed_outputs = rotate(processed_outputs).to('cpu')
92
 
93
  output_array = processed_outputs.squeeze().detach().numpy().astype(np.uint8)
94
 
 
72
 
73
 
74
  def load_and_segment_image(input_image_path, device):
 
75
  image_tensor = pre_transforms(input_image_path)
76
  image_tensor = image_tensor.unsqueeze(0).to(device)
77
 
 
83
 
84
  outputs = outputs.squeeze(0)
85
 
86
+ processed_outputs = post_transforms(outputs).to('cpu')
 
 
 
 
87
 
88
  output_array = processed_outputs.squeeze().detach().numpy().astype(np.uint8)
89
 
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 = Image.open(image_path).convert('L')
84
- original_image_np = np.array(original_image)
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: