Skip to content

Commit 1b666c5

Browse files
committed
Add support to create attributes from Image kwargs
1 parent 9d1b3b2 commit 1b666c5

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

src/torchio/data/image.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,8 @@ def __init__(
181181
self[STEM] = '' if self.path is None else get_stem(self.path)
182182
self[TYPE] = type
183183

184+
self.update_attributes()
185+
184186
def __repr__(self):
185187
properties = []
186188
properties.extend(
@@ -233,6 +235,10 @@ def __copy__(self):
233235
)
234236
return new_image
235237

238+
def update_attributes(self) -> None:
239+
# This allows to get images using attribute notation, e.g. image.modality
240+
self.__dict__.update(self)
241+
236242
@staticmethod
237243
def _check_data_loader() -> None:
238244
if torch.__version__ >= '2.3' and in_torch_loader():

0 commit comments

Comments
 (0)