Skip to content

Commit

Permalink
Fix padding bug when image depth is smaller than 6 during prediction (#…
Browse files Browse the repository at this point in the history
…155)

- We added a padding of (6, 6) across the last dimension to avoid artefacts
  • Loading branch information
HangJung97 authored Feb 21, 2024
1 parent d1df261 commit cf3df50
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion ascent/models/nnunet_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -494,10 +494,14 @@ def predict(
if len(image.shape) == 5:
if len(self.patch_size) == 3:
# Pad the last dimension to avoid 3D segmentation border artifacts
extra_pad = 0
while image.shape[-1] <= 6:
image = pad(image, (1, 1, 0, 0, 0, 0), mode="reflect")
extra_pad += 1
image = pad(image, (6, 6, 0, 0, 0, 0), mode="reflect")
pred = self.predict_3D_3Dconv_tiled(image, apply_softmax)
# Inverse the padding after prediction
return pred[..., 6:-6]
return pred[..., (6 + extra_pad) : (-6 - extra_pad)]
elif len(self.patch_size) == 2:
return self.predict_3D_2Dconv_tiled(image, apply_softmax)
else:
Expand Down

0 comments on commit cf3df50

Please sign in to comment.