@@ -159,19 +159,27 @@ class ITKReader(ImageReader):
159
159
If ``False``, the spatial indexing follows the numpy convention;
160
160
otherwise, the spatial indexing convention is reversed to be compatible with ITK. Default is ``False``.
161
161
This option does not affect the metadata.
162
+ series_meta: whether to load the metadata of the DICOM series (using the metadata from the first slice).
163
+ This flag is checked only when loading DICOM series. Default is ``False``.
162
164
kwargs: additional args for `itk.imread` API. more details about available args:
163
165
https://github.com/InsightSoftwareConsortium/ITK/blob/master/Wrapping/Generators/Python/itk/support/extras.py
164
166
165
167
"""
166
168
167
169
def __init__ (
168
- self , channel_dim : Optional [int ] = None , series_name : str = "" , reverse_indexing : bool = False , ** kwargs
170
+ self ,
171
+ channel_dim : Optional [int ] = None ,
172
+ series_name : str = "" ,
173
+ reverse_indexing : bool = False ,
174
+ series_meta : bool = False ,
175
+ ** kwargs ,
169
176
):
170
177
super ().__init__ ()
171
178
self .kwargs = kwargs
172
179
self .channel_dim = channel_dim
173
180
self .series_name = series_name
174
181
self .reverse_indexing = reverse_indexing
182
+ self .series_meta = series_meta
175
183
176
184
def verify_suffix (self , filename : Union [Sequence [PathLike ], PathLike ]) -> bool :
177
185
"""
@@ -221,7 +229,17 @@ def read(self, data: Union[Sequence[PathLike], PathLike], **kwargs):
221
229
series_identifier = series_uid [0 ] if not self .series_name else self .series_name
222
230
name = names_generator .GetFileNames (series_identifier )
223
231
224
- img_ .append (itk .imread (name , ** kwargs_ ))
232
+ _obj = itk .imread (name , ** kwargs_ )
233
+ if self .series_meta :
234
+ _reader = itk .ImageSeriesReader .New (FileNames = name )
235
+ _reader .Update ()
236
+ _meta = _reader .GetMetaDataDictionaryArray ()
237
+ if len (_meta ) > 0 :
238
+ # TODO: using the first slice's meta. this could be improved to filter unnecessary tags.
239
+ _obj .SetMetaDataDictionary (_meta [0 ])
240
+ img_ .append (_obj )
241
+ else :
242
+ img_ .append (itk .imread (name , ** kwargs_ ))
225
243
return img_ if len (filenames ) > 1 else img_ [0 ]
226
244
227
245
def get_data (self , img ):
0 commit comments