Skip to content

Commit

Permalink
Improve error message about shape mismatch
Browse files Browse the repository at this point in the history
  • Loading branch information
fepegar committed Sep 5, 2021
1 parent c41f842 commit 512eeab
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
17 changes: 13 additions & 4 deletions torchio/data/subject.py
Expand Up @@ -302,10 +302,19 @@ def check_consistent_affine(self) -> None:
self.check_consistent_attribute('affine')

def check_consistent_space(self) -> None:
self.check_consistent_spatial_shape()
self.check_consistent_attribute('origin')
self.check_consistent_attribute('direction')
self.check_consistent_attribute('spacing')
try:
self.check_consistent_attribute('spacing')
self.check_consistent_attribute('direction')
self.check_consistent_attribute('origin')
self.check_consistent_spatial_shape()
except RuntimeError as e:
message = (
'As described above, some images in the subject are not in the'
' same space. You probably can use the tranforms ToCanonical'
' and Resample to fix this, as explained at'
' https://github.com/fepegar/torchio/issues/647#issuecomment-913025695'
)
raise RuntimeError(message) from e

def get_images_names(self) -> List[str]:
return list(self.get_images_dict(intensity_only=False).keys())
Expand Down
1 change: 1 addition & 0 deletions torchio/transforms/preprocessing/spatial/crop_or_pad.py
Expand Up @@ -237,6 +237,7 @@ def _compute_mask_center_crop_or_pad(
return padding_params, cropping_params

def apply_transform(self, subject: Subject) -> Subject:
subject.check_consistent_space()
padding_params, cropping_params = self.compute_crop_or_pad(subject)
padding_kwargs = {'padding_mode': self.padding_mode}
if padding_params is not None:
Expand Down

0 comments on commit 512eeab

Please sign in to comment.