Get all the metadata of the image and convert to dict type. Args: img: an ITK image object loaded from an image file.
(self, img)
| 310 | return _stack_images(img_array, compatible_meta), compatible_meta |
| 311 | |
| 312 | def _get_meta_dict(self, img) -> dict: |
| 313 | """ |
| 314 | Get all the metadata of the image and convert to dict type. |
| 315 | |
| 316 | Args: |
| 317 | img: an ITK image object loaded from an image file. |
| 318 | |
| 319 | """ |
| 320 | img_meta_dict = img.GetMetaDataDictionary() |
| 321 | meta_dict = {} |
| 322 | for key in img_meta_dict.GetKeys(): |
| 323 | if key.startswith("ITK_"): |
| 324 | continue |
| 325 | val = img_meta_dict[key] |
| 326 | meta_dict[key] = np.asarray(val) if type(val).__name__.startswith("itk") else val |
| 327 | |
| 328 | meta_dict["spacing"] = np.asarray(img.GetSpacing()) |
| 329 | return meta_dict |
| 330 | |
| 331 | def _get_affine(self, img, lps_to_ras: bool = True): |
| 332 | """ |