File size: 1,278 Bytes
7fcd965 62785f9 7fcd965 62785f9 7fcd965 62785f9 953afb3 7fcd965 62785f9 953afb3 7fcd965 953afb3 62785f9 953afb3 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | """Metadata utilities for the binary coronary segmentation bundle."""
from typing import Dict, Hashable, Mapping, Union
from monai.config.type_definitions import KeysCollection
from monai.data.meta_tensor import MetaTensor
from monai.transforms import MapTransform
class CopyMetadatad(MapTransform):
"""
Copy MetaData from one MetaTensor to another.
Args:
keys: The keys that correspond to the MetaTensors to update.
reference_key: The key that corresponds to the MetaTensor providing the metadict.
allow_missing_keys: Whether to allow missing keys.
"""
def __init__(
self,
keys: KeysCollection,
reference_key: KeysCollection,
allow_missing_keys: bool = False,
) -> None:
super().__init__(keys, allow_missing_keys)
self.reference_key = reference_key
def __call__(self, data: Mapping) -> Dict[Hashable, Union[Dict, MetaTensor]]:
d = dict(data)
ref = d[self.reference_key]
for key in self.key_iterator(d):
if isinstance(d[key], MetaTensor):
d[key].meta = ref.meta.copy()
if hasattr(ref, "applied_operations"):
d[key].applied_operations = ref.applied_operations.copy()
return d
|