andreped commited on
Commit
841a460
1 Parent(s): 143fc81

typo fix '.ini' instead of '.nii'. Also fixed casting to reduce memory usage

Browse files
Files changed (1) hide show
  1. livermask/livermask.py +9 -9
livermask/livermask.py CHANGED
@@ -70,7 +70,7 @@ def func(path, output, cpu, verbose):
70
 
71
  for curr in tqdm(paths, "CT:"):
72
  # check if current file is a nifti file, if not, skip
73
- if not curr.endswith(".ini"):
74
  continue
75
 
76
  log.info("preprocessing...")
@@ -110,12 +110,12 @@ def func(path, output, cpu, verbose):
110
  log.info("resize back...")
111
  # resize back from 512x512
112
  pred = zoom(pred, [curr_shape[0] / img_size, curr_shape[1] / img_size, 1.0], order=1)
113
- pred = (pred >= 0.5).astype(np.float32)
114
 
115
  log.info("morphological post-processing...")
116
  # morpological post-processing
117
  # 1) first erode
118
- pred = binary_erosion(pred.astype(bool), ball(3)).astype(np.float32)
119
 
120
  # 2) keep only largest connected component
121
  labels = label(pred)
@@ -133,7 +133,7 @@ def func(path, output, cpu, verbose):
133
  pred = binary_dilation(pred.astype(bool), ball(3))
134
 
135
  # 4) remove small holes
136
- pred = remove_small_holes(pred.astype(bool), area_threshold=0.001*np.prod(pred.shape)).astype(np.float32)
137
 
138
  log.info("saving...")
139
  pred = pred.astype(np.uint8)
@@ -173,19 +173,19 @@ def main():
173
  # Memory growth must be set before GPUs have been initialized
174
  print(e)
175
 
 
 
 
 
176
  if ret.input is None:
177
  raise ValueError("Please, provide an input.")
178
  if ret.output is None:
179
  raise ValueError("Please, provide an output.")
180
  if not os.path.isdir(ret.input) and not ret.input.endswith(".nii"):
181
  raise ValueError("Input path provided is not in the supported '.nii' format or a directory.")
182
- if ret.output.endswith(".nii") or not os.path.isdir(ret.output) or "." in ret.output.split("/")[-1]:
183
  raise ValueError("Output path provided is not a directory or a name (remove *.nii format from name).")
184
 
185
- # fix paths
186
- ret.input = ret.input.replace("\\", "/")
187
- ret.output = ret.output.replace("\\", "/")
188
-
189
  func(*vars(ret).values())
190
 
191
 
 
70
 
71
  for curr in tqdm(paths, "CT:"):
72
  # check if current file is a nifti file, if not, skip
73
+ if not curr.endswith(".nii"):
74
  continue
75
 
76
  log.info("preprocessing...")
 
110
  log.info("resize back...")
111
  # resize back from 512x512
112
  pred = zoom(pred, [curr_shape[0] / img_size, curr_shape[1] / img_size, 1.0], order=1)
113
+ pred = (pred >= 0.5).astype(bool)
114
 
115
  log.info("morphological post-processing...")
116
  # morpological post-processing
117
  # 1) first erode
118
+ pred = binary_erosion(pred, ball(3)).astype(np.int32)
119
 
120
  # 2) keep only largest connected component
121
  labels = label(pred)
 
133
  pred = binary_dilation(pred.astype(bool), ball(3))
134
 
135
  # 4) remove small holes
136
+ pred = remove_small_holes(pred.astype(bool), area_threshold=0.001 * np.prod(pred.shape))
137
 
138
  log.info("saving...")
139
  pred = pred.astype(np.uint8)
 
173
  # Memory growth must be set before GPUs have been initialized
174
  print(e)
175
 
176
+ # fix paths
177
+ ret.input = ret.input.replace("\\", "/")
178
+ ret.output = ret.output.replace("\\", "/")
179
+
180
  if ret.input is None:
181
  raise ValueError("Please, provide an input.")
182
  if ret.output is None:
183
  raise ValueError("Please, provide an output.")
184
  if not os.path.isdir(ret.input) and not ret.input.endswith(".nii"):
185
  raise ValueError("Input path provided is not in the supported '.nii' format or a directory.")
186
+ if ret.output.endswith(".nii") or "." in ret.output.split("/")[-1]:
187
  raise ValueError("Output path provided is not a directory or a name (remove *.nii format from name).")
188
 
 
 
 
 
189
  func(*vars(ret).values())
190
 
191