Skip to content

Commit

Permalink
Add support for metatensor in AddGuidanceFromPointsDeepEditd and Resi…
Browse files Browse the repository at this point in the history
…zeGuidanceMultipleLabelDeepEditd (#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 <[email protected]>
  • Loading branch information
KumoLiu authored Oct 11, 2023
1 parent 8d730cd commit 2b1e3d0
Showing 1 changed file with 25 additions and 5 deletions.
30 changes: 25 additions & 5 deletions monai/apps/deepedit/transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -662,13 +662,21 @@ def _apply(clicks, factor):
def __call__(self, data):
d = dict(data)
meta_dict_key = self.meta_keys or f"{self.ref_image}_{self.meta_key_postfix}"
if meta_dict_key not in d:
raise RuntimeError(f"Missing meta_dict {meta_dict_key} in data!")
if "spatial_shape" not in d[meta_dict_key]:
# extract affine matrix from metadata
if isinstance(d[self.ref_image], MetaTensor):
meta_dict = d[self.ref_image].meta # type: ignore
elif meta_dict_key in d:
meta_dict = d[meta_dict_key]
else:
raise ValueError(
f"{meta_dict_key} is not found. Please check whether it is the correct the image meta key."
)

if "spatial_shape" not in meta_dict:
raise RuntimeError('Missing "spatial_shape" in meta_dict!')

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

# in here we assume the depth dimension is in the last dimension of "original_shape" and "current_shape"
Expand Down Expand Up @@ -698,7 +706,19 @@ def __call__(self, data):
d = dict(data)
# Assume channel is first and depth is last CHWD
current_shape = d[self.ref_image].shape[1:]
original_shape = d["image_meta_dict"]["spatial_shape"]

meta_dict_key = "image_meta_dict"
# extract affine matrix from metadata
if isinstance(d[self.ref_image], MetaTensor):
meta_dict = d[self.ref_image].meta # type: ignore
elif meta_dict_key in d:
meta_dict = d[meta_dict_key]
else:
raise ValueError(
f"{meta_dict_key} is not found. Please check whether it is the correct the image meta key."
)

original_shape = meta_dict["spatial_shape"]

factor = np.divide(current_shape, original_shape)
all_guidances = {}
Expand Down

0 comments on commit 2b1e3d0

Please sign in to comment.