Skip to content

Commit

Permalink
Fix custom reader not propagated when copying (#1091)
Browse files Browse the repository at this point in the history
  • Loading branch information
fepegar authored Jun 14, 2023
1 parent bc8017c commit d906eb5
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/torchio/data/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,13 @@ def __copy__(self):
if key in PROTECTED_KEYS:
continue
kwargs[key] = value # should I copy? deepcopy?
return type(self)(**kwargs)
new_image_class = type(self)
new_image = new_image_class(
check_nans=self.check_nans,
reader=self.reader,
**kwargs,
)
return new_image

@property
def data(self) -> torch.Tensor:
Expand Down Expand Up @@ -252,7 +258,10 @@ def affine(self) -> np.ndarray:
"""Affine matrix to transform voxel indices into world coordinates."""
# If path is a dir (probably DICOM), just load the data
# Same if it's a list of paths (used to create a 4D image)
if self._loaded or self._is_dir() or self._is_multipath():
# Finally, if we use a custom reader, SimpleITK probably won't be able
# to read the metadata, so we resort to loading everything into memory
is_custom_reader = self.reader is not read_image
if self._loaded or self._is_dir() or self._is_multipath() or is_custom_reader:
affine = self[AFFINE]
else:
assert self.path is not None
Expand Down

0 comments on commit d906eb5

Please sign in to comment.