diff --git a/monai/transforms/utility/array.py b/monai/transforms/utility/array.py index 72dd189009..1b3c59afdb 100644 --- a/monai/transforms/utility/array.py +++ b/monai/transforms/utility/array.py @@ -1609,9 +1609,9 @@ def _check_all_values_uneven(self, x: tuple) -> None: def _check_filter_format(self, filter: str | NdarrayOrTensor | nn.Module, filter_size: int | None = None) -> None: if isinstance(filter, str): - if not filter_size: + if filter != "gauss" and not filter_size: # Gauss is the only filter that does not require `filter_size` raise ValueError("`filter_size` must be specified when specifying filters by string.") - if filter_size % 2 == 0: + if filter_size and filter_size % 2 == 0: raise ValueError("`filter_size` should be a single uneven integer.") if filter not in self.supported_filters: raise NotImplementedError(f"{filter}. Supported filters are {self.supported_filters}.") diff --git a/tests/test_image_filter.py b/tests/test_image_filter.py index 76e38d94f4..fb08b2295d 100644 --- a/tests/test_image_filter.py +++ b/tests/test_image_filter.py @@ -134,6 +134,12 @@ def test_pass_empty_metadata_dict(self): out_tensor = filter(image) self.assertTrue(isinstance(out_tensor, MetaTensor)) + def test_gaussian_filter_without_filter_size(self): + "Test Gaussian filter without specifying filter_size" + filter = ImageFilter("gauss", sigma=2) + out_tensor = filter(SAMPLE_IMAGE_2D) + self.assertEqual(out_tensor.shape[1:], SAMPLE_IMAGE_2D.shape[1:]) + class TestImageFilterDict(unittest.TestCase):