Skip to content

Commit 75c44e0

Browse files
authored
fix: handle metadata loading and shape calculation in transforms (#1990)
Fixes # . handle metadata loading and shape calculation in transforms ### Description - Add image_only=False and ensure_channel_first=True to LoadImaged transform to properly load metadata - Fix shape mismatch in PreprocessAnisotropic.calculate_new_shape by handling 4D input shapes - Addresses KeyError: 'image_meta_dict' and ValueError: operands could not be broadcast together Note: The metadata loading issue might be related to MONAI version differences. Current version: 1.4.0 ### Checks - [x] Avoid including large-size files in the PR. - [x] Clean up long text outputs from code cells in the notebook. - [x] For security purposes, please check the contents and remove any sensitive info such as user names and private key. --------- Signed-off-by: Tristan Kirscher <[email protected]>
1 parent 211cfd8 commit 75c44e0

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

modules/dynunet_pipeline/transforms.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@ def get_task_transforms(mode, task_id, pos_sample_num, neg_sample_num, num_sampl
4040
keys = ["image", "label"]
4141
else:
4242
keys = ["image"]
43-
43+
# 1. loading
4444
load_transforms = [
45-
LoadImaged(keys=keys),
45+
LoadImaged(keys=keys, image_only=False),
4646
EnsureChannelFirstd(keys=keys),
4747
]
4848
# 2. sampling
@@ -284,6 +284,8 @@ def __init__(
284284

285285
def calculate_new_shape(self, spacing, shape):
286286
spacing_ratio = np.array(spacing) / np.array(self.target_spacing)
287+
if len(shape) == 4: # If shape includes channel dimension
288+
shape = shape[1:]
287289
new_shape = (spacing_ratio * np.array(shape)).astype(int).tolist()
288290
return new_shape
289291

0 commit comments

Comments
 (0)