Skip to content

Commit

Permalink
Change name of label filter class (Project-MONAI#2678)
Browse files Browse the repository at this point in the history
Signed-off-by: Sebastian Penhouet <sebastian.penhouet@airamed.de>
  • Loading branch information
Sebastian Penhouet committed Aug 6, 2021
1 parent 7ef566d commit 201bef0
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 25 deletions.
8 changes: 4 additions & 4 deletions docs/source/transforms.rst
Original file line number Diff line number Diff line change
Expand Up @@ -356,9 +356,9 @@ Post-processing
:members:
:special-members: __call__

`Filter`
`LabelFilter`
"""""""""""""""""""""""""""""""
.. autoclass:: Filter
.. autoclass:: LabelFilter
:members:
:special-members: __call__

Expand Down Expand Up @@ -967,9 +967,9 @@ Post-processing (Dict)
:members:
:special-members: __call__

`Filterd`
`LabelFilterd`
""""""""""""""""""""""""""""""""
.. autoclass:: Filterd
.. autoclass:: LabelFilterd
:members:
:special-members: __call__

Expand Down
8 changes: 4 additions & 4 deletions monai/transforms/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,8 @@
Activations,
AsDiscrete,
FillHoles,
Filter,
KeepLargestConnectedComponent,
LabelFilter,
LabelToContour,
MeanEnsemble,
ProbNMS,
Expand All @@ -213,15 +213,15 @@
FillHolesD,
FillHolesd,
FillHolesDict,
FilterD,
Filterd,
FilterDict,
InvertD,
Invertd,
InvertDict,
KeepLargestConnectedComponentD,
KeepLargestConnectedComponentd,
KeepLargestConnectedComponentDict,
LabelFilterD,
LabelFilterd,
LabelFilterDict,
LabelToContourD,
LabelToContourd,
LabelToContourDict,
Expand Down
10 changes: 5 additions & 5 deletions monai/transforms/post/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
"Activations",
"AsDiscrete",
"FillHoles",
"Filter",
"KeepLargestConnectedComponent",
"LabelFilter",
"LabelToContour",
"MeanEnsemble",
"ProbNMS",
Expand Down Expand Up @@ -292,7 +292,7 @@ def __call__(self, img: torch.Tensor) -> torch.Tensor:
return output


class Filter:
class LabelFilter:
"""
This transform filters out labels and can be used as a processing step to view only certain labels.
Expand All @@ -303,7 +303,7 @@ class Filter:
For example:
Use Filter with applied_labels=[1, 5, 9]::
Use LabelFilter with applied_labels=[1, 5, 9]::
[1, 2, 3] [1, 0, 0]
[4, 5, 6] => [0, 5 ,0]
Expand All @@ -312,7 +312,7 @@ class Filter:

def __init__(self, applied_labels: Union[Sequence[int], int]) -> None:
"""
Initialize the Filter class with the labels to filter on.
Initialize the LabelFilter class with the labels to filter on.
Args:
applied_labels (Union[Sequence[int], int]): Label(s) to filter on.
Expand Down Expand Up @@ -416,7 +416,7 @@ def __call__(self, img: NdarrayTensor) -> NdarrayTensor:
img_arr = np.squeeze(img, axis=channel_axis)
output = get_filled_holes(img_arr, self.connectivity)
if self.applied_labels:
output = Filter(self.applied_labels)(output)
output = LabelFilter(self.applied_labels)(output)
output = np.expand_dims(output, axis=channel_axis)
output = img_arr + output
return output
Expand Down
16 changes: 8 additions & 8 deletions monai/transforms/post/dictionary.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
Activations,
AsDiscrete,
FillHoles,
Filter,
KeepLargestConnectedComponent,
LabelFilter,
LabelToContour,
MeanEnsemble,
ProbNMS,
Expand All @@ -53,15 +53,15 @@
"FillHolesD",
"FillHolesDict",
"FillHolesd",
"FilterD",
"FilterDict",
"Filterd",
"InvertD",
"InvertDict",
"Invertd",
"KeepLargestConnectedComponentD",
"KeepLargestConnectedComponentDict",
"KeepLargestConnectedComponentd",
"LabelFilterD",
"LabelFilterDict",
"LabelFilterd",
"LabelToContourD",
"LabelToContourDict",
"LabelToContourd",
Expand Down Expand Up @@ -216,9 +216,9 @@ def __call__(self, data: Mapping[Hashable, torch.Tensor]) -> Dict[Hashable, torc
return d


class Filterd(MapTransform):
class LabelFilterd(MapTransform):
"""
Dictionary-based wrapper of :py:class:`monai.transforms.Filter`.
Dictionary-based wrapper of :py:class:`monai.transforms.LabelFilter`.
"""

def __init__(
Expand All @@ -236,7 +236,7 @@ def __init__(
"""
super().__init__(keys, allow_missing_keys)
self.converter = Filter(applied_labels)
self.converter = LabelFilter(applied_labels)

def __call__(self, data: Mapping[Hashable, NdarrayTensor]) -> Dict[Hashable, NdarrayTensor]:
d = dict(data)
Expand Down Expand Up @@ -692,9 +692,9 @@ def get_saver(self):
ActivationsD = ActivationsDict = Activationsd
AsDiscreteD = AsDiscreteDict = AsDiscreted
FillHolesD = FillHolesDict = FillHolesd
FilterD = FilterDict = Filterd
InvertD = InvertDict = Invertd
KeepLargestConnectedComponentD = KeepLargestConnectedComponentDict = KeepLargestConnectedComponentd
LabelFilterD = LabelFilterDict = LabelFilterd
LabelToContourD = LabelToContourDict = LabelToContourd
MeanEnsembleD = MeanEnsembleDict = MeanEnsembled
ProbNMSD = ProbNMSDict = ProbNMSd
Expand Down
8 changes: 4 additions & 4 deletions tests/test_filter.py → tests/test_label_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import torch
from parameterized import parameterized

from monai.transforms import Filter
from monai.transforms import LabelFilter
from tests.utils import allclose, clone

grid_1 = torch.tensor(
Expand Down Expand Up @@ -102,10 +102,10 @@
INVALID_CASES = [ITEST_CASE_1]


class TestFillHoles(unittest.TestCase):
class TestLabelFilter(unittest.TestCase):
@parameterized.expand(VALID_CASES)
def test_correct_results(self, _, args, input_image, expected):
converter = Filter(**args)
converter = LabelFilter(**args)
if isinstance(input_image, torch.Tensor) and torch.cuda.is_available():
result = converter(clone(input_image).cuda())
assert allclose(result, expected.cuda())
Expand All @@ -116,7 +116,7 @@ def test_correct_results(self, _, args, input_image, expected):
@parameterized.expand(INVALID_CASES)
def test_raise_exception(self, _, args, input_image, expected_error):
with self.assertRaises(expected_error):
converter = Filter(**args)
converter = LabelFilter(**args)
if isinstance(input_image, torch.Tensor) and torch.cuda.is_available():
_ = converter(clone(input_image).cuda())
else:
Expand Down

0 comments on commit 201bef0

Please sign in to comment.