Hemaxi commited on
Commit
4475117
·
verified ·
1 Parent(s): f7a8dfa

Update prediction.py

Browse files
Files changed (1) hide show
  1. prediction.py +18 -1
prediction.py CHANGED
@@ -8,6 +8,8 @@ from tqdm import tqdm
8
  import warnings
9
  warnings.filterwarnings("ignore")
10
  from huggingface_hub import hf_hub_download
 
 
11
 
12
 
13
  def predict_mask(image, dim_x, dim_y, dim_z, _resize=True, norm_=True, mode_='test', patch_size=(64,128,128,1), _step=64, _step_z=32, _patch_size_z=64):
@@ -144,4 +146,19 @@ def predict_mask(image, dim_x, dim_y, dim_z, _resize=True, norm_=True, mode_='te
144
  final_mask = final_mask*255.0
145
  final_mask = final_mask.astype('uint8')
146
 
147
- return final_mask
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8
  import warnings
9
  warnings.filterwarnings("ignore")
10
  from huggingface_hub import hf_hub_download
11
+ from skimage.morphology import binary_erosion, binary_dilation
12
+ from skimage import draw
13
 
14
 
15
  def predict_mask(image, dim_x, dim_y, dim_z, _resize=True, norm_=True, mode_='test', patch_size=(64,128,128,1), _step=64, _step_z=32, _patch_size_z=64):
 
146
  final_mask = final_mask*255.0
147
  final_mask = final_mask.astype('uint8')
148
 
149
+
150
+ #closing operation to fill small holes
151
+ mask = final_mask
152
+ mask[mask!=0] = 1
153
+ mask = mask.astype('uint8')
154
+
155
+ ellipsoid = draw.ellipsoid(9,9,3, spacing=(1,1,1), levelset=False)
156
+ ellipsoid = ellipsoid.astype('uint8')
157
+ ellipsoid = ellipsoid[1:-1,1:-1,1:-1]
158
+
159
+ #perform closing operation on the mask
160
+ dil = binary_dilation(mask, ellipsoid)
161
+ closed_mask = binary_erosion(dil, ellipsoid)
162
+ closed_mask = (closed_mask*255.0).astype('uint8')
163
+
164
+ return closed_mask