Skip to content

Commit

Permalink
Merge branch 'dev' into update-changelog
Browse files Browse the repository at this point in the history
  • Loading branch information
wyli authored Oct 11, 2023
2 parents 7902138 + 2b1e3d0 commit da7631c
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 da7631c

Please sign in to comment.