diff --git a/src/torchio/data/image.py b/src/torchio/data/image.py index ff9506f8..5e4fe1d3 100644 --- a/src/torchio/data/image.py +++ b/src/torchio/data/image.py @@ -181,6 +181,8 @@ def __init__( self[STEM] = '' if self.path is None else get_stem(self.path) self[TYPE] = type + self.update_attributes() + def __repr__(self): properties = [] properties.extend( @@ -233,6 +235,10 @@ def __copy__(self): ) return new_image + def update_attributes(self) -> None: + # This allows to get images using attribute notation, e.g. image.modality + self.__dict__.update(self) + @staticmethod def _check_data_loader() -> None: if torch.__version__ >= '2.3' and in_torch_loader():