Skip to content

Commit 2b1e3d0

Browse files
authored
Add support for metatensor in AddGuidanceFromPointsDeepEditd and ResizeGuidanceMultipleLabelDeepEditd (#7115)
Fixes #7114 ### Types of changes <!--- Put an `x` in all the boxes that apply, and remove the not applicable items --> - [x] Non-breaking change (fix or new feature that would not break existing functionality). - [ ] Breaking change (fix or new feature that would cause existing functionality to change). - [ ] New tests added to cover the changes. - [ ] Integration tests passed locally by running `./runtests.sh -f -u --net --coverage`. - [ ] Quick tests passed locally by running `./runtests.sh --quick --unittests --disttests`. - [ ] In-line docstrings updated. - [ ] Documentation updated, tested `make html` command in the `docs/` folder. --------- Signed-off-by: KumoLiu <yunl@nvidia.com>
1 parent 8d730cd commit 2b1e3d0

File tree

1 file changed

+25
-5
lines changed

1 file changed

+25
-5
lines changed

monai/apps/deepedit/transforms.py

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -662,13 +662,21 @@ def _apply(clicks, factor):
662662
def __call__(self, data):
663663
d = dict(data)
664664
meta_dict_key = self.meta_keys or f"{self.ref_image}_{self.meta_key_postfix}"
665-
if meta_dict_key not in d:
666-
raise RuntimeError(f"Missing meta_dict {meta_dict_key} in data!")
667-
if "spatial_shape" not in d[meta_dict_key]:
665+
# extract affine matrix from metadata
666+
if isinstance(d[self.ref_image], MetaTensor):
667+
meta_dict = d[self.ref_image].meta # type: ignore
668+
elif meta_dict_key in d:
669+
meta_dict = d[meta_dict_key]
670+
else:
671+
raise ValueError(
672+
f"{meta_dict_key} is not found. Please check whether it is the correct the image meta key."
673+
)
674+
675+
if "spatial_shape" not in meta_dict:
668676
raise RuntimeError('Missing "spatial_shape" in meta_dict!')
669677

670678
# Assume channel is first and depth is last CHWD
671-
original_shape = d[meta_dict_key]["spatial_shape"]
679+
original_shape = meta_dict["spatial_shape"]
672680
current_shape = list(d[self.ref_image].shape)[1:]
673681

674682
# in here we assume the depth dimension is in the last dimension of "original_shape" and "current_shape"
@@ -698,7 +706,19 @@ def __call__(self, data):
698706
d = dict(data)
699707
# Assume channel is first and depth is last CHWD
700708
current_shape = d[self.ref_image].shape[1:]
701-
original_shape = d["image_meta_dict"]["spatial_shape"]
709+
710+
meta_dict_key = "image_meta_dict"
711+
# extract affine matrix from metadata
712+
if isinstance(d[self.ref_image], MetaTensor):
713+
meta_dict = d[self.ref_image].meta # type: ignore
714+
elif meta_dict_key in d:
715+
meta_dict = d[meta_dict_key]
716+
else:
717+
raise ValueError(
718+
f"{meta_dict_key} is not found. Please check whether it is the correct the image meta key."
719+
)
720+
721+
original_shape = meta_dict["spatial_shape"]
702722

703723
factor = np.divide(current_shape, original_shape)
704724
all_guidances = {}

0 commit comments

Comments
 (0)