Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ImageFilter to allow Gaussian filter without filter_size #8189

Open
wants to merge 5 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions monai/transforms/utility/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}.")
Expand Down
6 changes: 6 additions & 0 deletions tests/test_image_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):

Expand Down
Loading