Skip to content

Commit e499362

Browse files
IamTingTingKumoLiu
andauthored
add kwargs in array and functional file (#8508)
Fixes #8492 ### Description This PR adds support for `**kwargs` in the `ResizeWithPadOrCrop` transform to fix the issue where extra keyword arguments were ignored, causing errors in some workflows. ### 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. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Enhanced zoom functionality to support additional parameters, allowing for greater flexibility in image transformation operations. * **Refactor** * Improved handling of optional arguments in zoom-related transformations for more customizable behavior. <!-- end of auto-generated comment: release notes by coderabbit.ai --> Signed-off-by: IamTingTing <[email protected]> Co-authored-by: YunLiu <[email protected]>
1 parent 4b69748 commit e499362

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

monai/transforms/spatial/array.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1108,6 +1108,7 @@ def __call__(
11081108
_dtype,
11091109
lazy=lazy_,
11101110
transform_info=self.get_transform_info(),
1111+
**self.kwargs,
11111112
)
11121113

11131114
def inverse(self, data: torch.Tensor) -> torch.Tensor:

monai/transforms/spatial/functional.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ def rotate(img, angle, output_shape, mode, padding_mode, align_corners, dtype, l
411411
return out.copy_meta_from(meta_info) if isinstance(out, MetaTensor) else out
412412

413413

414-
def zoom(img, scale_factor, keep_size, mode, padding_mode, align_corners, dtype, lazy, transform_info):
414+
def zoom(img, scale_factor, keep_size, mode, padding_mode, align_corners, dtype, lazy, transform_info, **kwargs):
415415
"""
416416
Functional implementation of zoom.
417417
This function operates eagerly or lazily according to
@@ -450,7 +450,7 @@ def zoom(img, scale_factor, keep_size, mode, padding_mode, align_corners, dtype,
450450
if keep_size:
451451
do_pad_crop = not np.allclose(output_size, im_shape)
452452
if do_pad_crop and lazy: # update for lazy evaluation
453-
_pad_crop = ResizeWithPadOrCrop(spatial_size=im_shape, mode=padding_mode)
453+
_pad_crop = ResizeWithPadOrCrop(spatial_size=im_shape, mode=padding_mode, **kwargs)
454454
_pad_crop.lazy = True
455455
_tmp_img = MetaTensor([], affine=torch.eye(len(output_size) + 1))
456456
_tmp_img.push_pending_operation({LazyAttr.SHAPE: list(output_size), LazyAttr.AFFINE: xform})
@@ -486,7 +486,7 @@ def zoom(img, scale_factor, keep_size, mode, padding_mode, align_corners, dtype,
486486
out = out.copy_meta_from(meta_info)
487487
do_pad_crop = not np.allclose(output_size, zoomed.shape[1:])
488488
if do_pad_crop:
489-
_pad_crop = ResizeWithPadOrCrop(spatial_size=img_t.shape[1:], mode=padding_mode)
489+
_pad_crop = ResizeWithPadOrCrop(spatial_size=img_t.shape[1:], mode=padding_mode, **kwargs)
490490
out = _pad_crop(out)
491491
if get_track_meta() and do_pad_crop:
492492
padcrop_xform = out.applied_operations.pop()

0 commit comments

Comments
 (0)