Repository: Project-MONAI/MONAI

Issue:
support One-Hot input in KeepLargestConnectedComponent
**Is your feature request related to a problem? Please describe.**
The current implementation of `KeepLargestConnectedComponent` can only support 1 channel input for the `multi-classes task`, need to enhance it for One-Hot format input with several channels.



Discussion:
Mark: I have discussed this task with Yuan-Ting offline, he is working on it now.
Thanks.

Patch:
diff --git a/monai/transforms/post/array.py b/monai/transforms/post/array.py
--- a/monai/transforms/post/array.py
+++ b/monai/transforms/post/array.py
@@ -19,6 +19,7 @@
 from monai.transforms.compose import Transform
 from monai.networks.utils import one_hot
 from monai.transforms.utils import get_largest_connected_component_mask
+from monai.utils.misc import ensure_tuple
 
 
 class SplitChannel(Transform):
@@ -144,18 +145,23 @@ class KeepLargestConnectedComponent(Transform):
     """
     Keeps only the largest connected component in the image.
     This transform can be used as a post-processing step to clean up over-segment areas in model output.
-    The input is assumed to be a PyTorch Tensor with shape (batch_size, 1, spatial_dim1[, spatial_dim2, ...])
 
-    Expected input data should have only 1 channel and the values correspond to expected labels.
+    The input is assumed to be a PyTorch Tensor:
+      1) With shape (batch_size, 1, spatial_dim1[, spatial_dim2, ...]) and the values correspond to expected labels.
+      2) With shape (batch_size, C, spatial_dim1[, spatial_dim2, ...]) and the values should be 0, 1 on each labels.
+
+    Note:
+        For single channel data, 0 will be treated as background and the over-segment pixels will be set to 0.
+        For one-hot data, the over-segment pixels will be set to 0 in its channel.
 
     For example:
-    Use KeepLargestConnectedComponent with applied_values=[1], connectivity=1
+    Use KeepLargestConnectedComponent with applied_labels=[1], connectivity=1
 
        [1, 0, 0]         [0, 0, 0]
        [0, 1, 1]    =>   [0, 1 ,1]
        [0, 1, 1]         [0, 1, 1]
 
-    Use KeepLargestConnectedComponent with applied_values[1, 2], independent=False, connectivity=1
+    Use KeepLargestConnectedComponent with applied_labels[1, 2], independent=False, connectivity=1
 
       [0, 0, 1, 0 ,0]           [0, 0, 1, 0 ,0]
       [0, 2, 1, 1 ,1]           [0, 2, 1, 1 ,1]
@@ -163,7 +169,7 @@ class KeepLargestConnectedComponent(Transform):
       [1, 2, 0, 1 ,0]           [1, 2, 0, 0 ,0]
       [2, 2, 0, 0 ,2]           [2, 2, 0, 0 ,0]
 
-    Use KeepLargestConnectedComponent with applied_values[1, 2], independent=True, connectivity=1
+    Use KeepLargestConnectedComponent with applied_labels[1, 2], independent=True, connectivity=1
 
       [0, 0, 1, 0 ,0]           [0, 0, 1, 0 ,0]
       [0, 2, 1, 1 ,1]           [0, 2, 1, 1 ,1]
@@ -171,7 +177,7 @@ class KeepLargestConnectedComponent(Transform):
       [1, 2, 0, 1 ,0]           [0, 2, 0, 0 ,0]
       [2, 2, 0, 0 ,2]           [2, 2, 0, 0 ,0]
 
-    Use KeepLargestConnectedComponent with applied_values[1, 2], independent=False, connectivity=2
+    Use KeepLargestConnectedComponent with applied_labels[1, 2], independent=False, connectivity=2
 
       [0, 0, 1, 0 ,0]           [0, 0, 1, 0 ,0]
       [0, 2, 1, 1 ,1]           [0, 2, 1, 1 ,1]
@@ -181,53 +187,64 @@ class KeepLargestConnectedComponent(Transform):
 
     """
 
-    def __init__(
-        self, applied_values, independent: bool = True, background: int = 0, connectivity: Optional[int] = None
-    ):
+    def __init__(self, applied_labels, independent: bool = True, connectivity: Optional[int] = None):
         """
         Args:
-            applied_values (list or tuple of int): number list for applying the connected component on.
-                The pixel whose value is not in this list will remain unchanged.
-            independent: consider several labels as a whole or independent, default is `True`.
+            applied_labels (int, list or tuple of int): Labels for applying the connected component on.
+                If only one channel. The pixel whose value is not in this list will remain unchanged.
+                If the data is in one-hot format, this is used to determine what channels to apply.
+            independent (bool): consider several labels as a whole or independent, default is `True`.
                 Example use case would be segment label 1 is liver and label 2 is liver tumor, in that case
                 you want this "independent" to be specified as False.
-            background: Background pixel value. The over-segmented pixels will be set as this value.
             connectivity: Maximum number of orthogonal hops to consider a pixel/voxel as a neighbor.
                 Accepted values are ranging from  1 to input.ndim. If ``None``, a full
                 connectivity of ``input.ndim`` is used.
         """
         super().__init__()
-        self.applied_values = applied_values
+        self.applied_labels = ensure_tuple(applied_labels)
         self.independent = independent
-        self.background = background
         self.connectivity = connectivity
-        if background in applied_values:
-            raise ValueError("Background pixel can't be in applied_values.")
 
     def __call__(self, img):
         """
         Args:
-            img: shape must be (batch_size, 1, spatial_dim1[, spatial_dim2, ...]).
+            img: shape must be (batch_size, C, spatial_dim1[, spatial_dim2, ...]).
 
         Returns:
-            A PyTorch Tensor with shape (batch_size, 1, spatial_dim1[, spatial_dim2, ...]).
+            A PyTorch Tensor with shape (batch_size, C, spatial_dim1[, spatial_dim2, ...]).
         """
         channel_dim = 1
         if img.shape[channel_dim] == 1:
+
             img = torch.squeeze(img, dim=channel_dim)
-        else:
-            raise ValueError("Input data have more than 1 channel.")
 
-        if self.independent:
-            for i in self.applied_values:
-                foreground = (img == i).type(torch.uint8)
+            if self.independent:
+                for i in self.applied_labels:
+                    foreground = (img == i).type(torch.uint8)
+                    mask = get_largest_connected_component_mask(foreground, self.connectivity)
+                    img[foreground != mask] = 0
+            else:
+                foreground = torch.zeros_like(img)
+                for i in self.applied_labels:
+                    foreground += (img == i).type(torch.uint8)
                 mask = get_largest_connected_component_mask(foreground, self.connectivity)
-                img[foreground != mask] = self.background
+                img[foreground != mask] = 0
+            output = torch.unsqueeze(img, dim=channel_dim)
         else:
-            foreground = torch.zeros_like(img)
-            for i in self.applied_values:
-                foreground += (img == i).type(torch.uint8)
-            mask = get_largest_connected_component_mask(foreground, self.connectivity)
-            img[foreground != mask] = self.background
+            # one-hot data is assumed to have binary value in each channel
+            if self.independent:
+                for i in self.applied_labels:
+                    foreground = img[:, i, ...].type(torch.uint8)
+                    mask = get_largest_connected_component_mask(foreground, self.connectivity)
+                    img[:, i, ...][foreground != mask] = 0
+            else:
+                applied_img = img[:, self.applied_labels, ...].type(torch.uint8)
+                foreground = torch.any(applied_img, dim=channel_dim)
+                mask = get_largest_connected_component_mask(foreground, self.connectivity)
+                background_mask = torch.unsqueeze(foreground != mask, dim=channel_dim)
+                background_mask = torch.repeat_interleave(background_mask, len(self.applied_labels), dim=channel_dim)
+                applied_img[background_mask] = 0
+                img[:, self.applied_labels, ...] = applied_img.type(img.type())
+            output = img
 
-        return torch.unsqueeze(img, dim=channel_dim)
+        return output
diff --git a/monai/transforms/post/dictionary.py b/monai/transforms/post/dictionary.py
--- a/monai/transforms/post/dictionary.py
+++ b/monai/transforms/post/dictionary.py
@@ -163,9 +163,8 @@ class KeepLargestConnectedComponentd(MapTransform):
     def __init__(
         self,
         keys: KeysCollection,
-        applied_values,
+        applied_labels,
         independent: bool = True,
-        background: int = 0,
         connectivity: Optional[int] = None,
         output_postfix: str = "largestcc",
     ):
@@ -173,12 +172,12 @@ def __init__(
         Args:
             keys: keys of the corresponding items to be transformed.
                 See also: :py:class:`monai.transforms.compose.MapTransform`
-            applied_values (list or tuple of int): number list for applying the connected component on.
-                The pixel whose value is not in this list will remain unchanged.
-            independent: consider several labels as a whole or independent, default is `True`.
+            applied_labels (int, list or tuple of int): Labels for applying the connected component on.
+                If only one channel. The pixel whose value is not in this list will remain unchanged.
+                If the data is in one-hot format, this is used to determine what channels to apply.
+            independent (bool): consider several labels as a whole or independent, default is `True`.
                 Example use case would be segment label 1 is liver and label 2 is liver tumor, in that case
                 you want this "independent" to be specified as False.
-            background: Background pixel value. The over-segmented pixels will be set as this value.
             connectivity: Maximum number of orthogonal hops to consider a pixel/voxel as a neighbor.
                 Accepted values are ranging from  1 to input.ndim. If ``None``, a full
                 connectivity of ``input.ndim`` is used.
@@ -191,7 +190,7 @@ def __init__(
         if output_postfix is not None and not isinstance(output_postfix, str):
             raise ValueError("output_postfix must be a string.")
         self.output_postfix = output_postfix
-        self.converter = KeepLargestConnectedComponent(applied_values, independent, background, connectivity)
+        self.converter = KeepLargestConnectedComponent(applied_labels, independent, connectivity)
 
     def __call__(self, data):
         d = dict(data)


Test patch:
diff --git a/tests/test_keep_largest_connected_component.py b/tests/test_keep_largest_connected_component.py
--- a/tests/test_keep_largest_connected_component.py
+++ b/tests/test_keep_largest_connected_component.py
@@ -18,97 +18,404 @@
 
 grid_1 = torch.tensor([[[[0, 0, 1, 0, 0], [0, 2, 1, 1, 1], [1, 2, 1, 0, 0], [1, 2, 0, 1, 0], [2, 2, 0, 0, 2]]]])
 grid_2 = torch.tensor([[[[0, 0, 0, 0, 1], [0, 0, 1, 1, 1], [1, 0, 1, 1, 2], [1, 0, 1, 2, 2], [0, 0, 0, 0, 1]]]])
+grid_3 = torch.tensor(
+    [
+        [
+            [
+                [1.0, 1.0, 0.0, 1.0, 1.0],
+                [1.0, 0.0, 0.0, 0.0, 0.0],
+                [0.0, 0.0, 0.0, 1.0, 1.0],
+                [0.0, 0.0, 1.0, 0.0, 1.0],
+                [0.0, 0.0, 1.0, 1.0, 0.0],
+            ],
+            [
+                [0.0, 0.0, 1.0, 0.0, 0.0],
+                [0.0, 0.0, 1.0, 1.0, 1.0],
+                [1.0, 0.0, 1.0, 0.0, 0.0],
+                [1.0, 0.0, 0.0, 1.0, 0.0],
+                [0.0, 0.0, 0.0, 0.0, 0.0],
+            ],
+            [
+                [0.0, 0.0, 0.0, 0.0, 0.0],
+                [0.0, 1.0, 0.0, 0.0, 0.0],
+                [0.0, 1.0, 0.0, 0.0, 0.0],
+                [0.0, 1.0, 0.0, 0.0, 0.0],
+                [1.0, 1.0, 0.0, 0.0, 1.0],
+            ],
+        ],
+        [
+            [
+                [1.0, 1.0, 1.0, 1.0, 0.0],
+                [1.0, 1.0, 0.0, 0.0, 0.0],
+                [0.0, 1.0, 0.0, 0.0, 0.0],
+                [0.0, 1.0, 0.0, 0.0, 0.0],
+                [1.0, 1.0, 1.0, 1.0, 0.0],
+            ],
+            [
+                [0.0, 0.0, 0.0, 0.0, 1.0],
+                [0.0, 0.0, 1.0, 1.0, 1.0],
+                [1.0, 0.0, 1.0, 1.0, 0.0],
+                [1.0, 0.0, 1.0, 0.0, 0.0],
+                [0.0, 0.0, 0.0, 0.0, 1.0],
+            ],
+            [
+                [0.0, 0.0, 0.0, 0.0, 0.0],
+                [0.0, 0.0, 0.0, 0.0, 0.0],
+                [0.0, 0.0, 0.0, 0.0, 1.0],
+                [0.0, 0.0, 0.0, 1.0, 1.0],
+                [0.0, 0.0, 0.0, 0.0, 0.0],
+            ],
+        ],
+    ]
+)
+
 
 TEST_CASE_1 = [
     "value_1",
-    {"independent": False, "applied_values": [1]},
+    {"independent": False, "applied_labels": 1},
     grid_1,
     torch.tensor([[[[0, 0, 1, 0, 0], [0, 2, 1, 1, 1], [0, 2, 1, 0, 0], [0, 2, 0, 1, 0], [2, 2, 0, 0, 2]]]]),
 ]
 
 TEST_CASE_2 = [
     "value_2",
-    {"independent": False, "applied_values": [2]},
+    {"independent": False, "applied_labels": [2]},
     grid_1,
     torch.tensor([[[[0, 0, 1, 0, 0], [0, 2, 1, 1, 1], [1, 2, 1, 0, 0], [1, 2, 0, 1, 0], [2, 2, 0, 0, 0]]]]),
 ]
 
 TEST_CASE_3 = [
     "independent_value_1_2",
-    {"independent": True, "applied_values": [1, 2]},
+    {"independent": True, "applied_labels": [1, 2]},
     grid_1,
     torch.tensor([[[[0, 0, 1, 0, 0], [0, 2, 1, 1, 1], [0, 2, 1, 0, 0], [0, 2, 0, 1, 0], [2, 2, 0, 0, 0]]]]),
 ]
 
 TEST_CASE_4 = [
     "dependent_value_1_2",
-    {"independent": False, "applied_values": [1, 2]},
+    {"independent": False, "applied_labels": [1, 2]},
     grid_1,
     torch.tensor([[[[0, 0, 1, 0, 0], [0, 2, 1, 1, 1], [1, 2, 1, 0, 0], [1, 2, 0, 1, 0], [2, 2, 0, 0, 2]]]]),
 ]
 
 TEST_CASE_5 = [
     "value_1",
-    {"independent": True, "applied_values": [1]},
+    {"independent": True, "applied_labels": [1]},
     grid_2,
     torch.tensor([[[[0, 0, 0, 0, 1], [0, 0, 1, 1, 1], [0, 0, 1, 1, 2], [0, 0, 1, 2, 2], [0, 0, 0, 0, 0]]]]),
 ]
 
 TEST_CASE_6 = [
     "independent_value_1_2",
-    {"independent": True, "applied_values": [1, 2]},
+    {"independent": True, "applied_labels": [1, 2]},
     grid_2,
     torch.tensor([[[[0, 0, 0, 0, 1], [0, 0, 1, 1, 1], [0, 0, 1, 1, 2], [0, 0, 1, 2, 2], [0, 0, 0, 0, 0]]]]),
 ]
 
 TEST_CASE_7 = [
     "dependent_value_1_2",
-    {"independent": False, "applied_values": [1, 2]},
+    {"independent": False, "applied_labels": [1, 2]},
     grid_2,
     torch.tensor([[[[0, 0, 0, 0, 1], [0, 0, 1, 1, 1], [0, 0, 1, 1, 2], [0, 0, 1, 2, 2], [0, 0, 0, 0, 1]]]]),
 ]
 
 TEST_CASE_8 = [
     "value_1_connect_1",
-    {"independent": False, "applied_values": [1], "connectivity": 1},
+    {"independent": False, "applied_labels": [1], "connectivity": 1},
     grid_1,
     torch.tensor([[[[0, 0, 1, 0, 0], [0, 2, 1, 1, 1], [0, 2, 1, 0, 0], [0, 2, 0, 0, 0], [2, 2, 0, 0, 2]]]]),
 ]
 
 TEST_CASE_9 = [
     "independent_value_1_2_connect_1",
-    {"independent": True, "applied_values": [1, 2], "connectivity": 1},
+    {"independent": True, "applied_labels": [1, 2], "connectivity": 1},
     grid_1,
     torch.tensor([[[[0, 0, 1, 0, 0], [0, 2, 1, 1, 1], [0, 2, 1, 0, 0], [0, 2, 0, 0, 0], [2, 2, 0, 0, 0]]]]),
 ]
 
 TEST_CASE_10 = [
     "dependent_value_1_2_connect_1",
-    {"independent": False, "applied_values": [1, 2], "connectivity": 1},
+    {"independent": False, "applied_labels": [1, 2], "connectivity": 1},
     grid_1,
     torch.tensor([[[[0, 0, 1, 0, 0], [0, 2, 1, 1, 1], [1, 2, 1, 0, 0], [1, 2, 0, 0, 0], [2, 2, 0, 0, 0]]]]),
 ]
 
 TEST_CASE_11 = [
-    "value_0_background_3",
-    {"independent": False, "applied_values": [0], "background": 3},
-    grid_1,
-    torch.tensor([[[[3, 3, 1, 3, 3], [3, 2, 1, 1, 1], [1, 2, 1, 0, 0], [1, 2, 0, 1, 0], [2, 2, 0, 0, 2]]]]),
+    "onehot_independent_batch_2_apply_label_1_connect_1",
+    {"independent": True, "applied_labels": [1], "connectivity": 1},
+    grid_3,
+    torch.tensor(
+        [
+            [
+                [
+                    [1.0, 1.0, 0.0, 1.0, 1.0],
+                    [1.0, 0.0, 0.0, 0.0, 0.0],
+                    [0.0, 0.0, 0.0, 1.0, 1.0],
+                    [0.0, 0.0, 1.0, 0.0, 1.0],
+                    [0.0, 0.0, 1.0, 1.0, 0.0],
+                ],
+                [
+                    [0.0, 0.0, 1.0, 0.0, 0.0],
+                    [0.0, 0.0, 1.0, 1.0, 1.0],
+                    [0.0, 0.0, 1.0, 0.0, 0.0],
+                    [0.0, 0.0, 0.0, 0.0, 0.0],
+                    [0.0, 0.0, 0.0, 0.0, 0.0],
+                ],
+                [
+                    [0.0, 0.0, 0.0, 0.0, 0.0],
+                    [0.0, 1.0, 0.0, 0.0, 0.0],
+                    [0.0, 1.0, 0.0, 0.0, 0.0],
+                    [0.0, 1.0, 0.0, 0.0, 0.0],
+                    [1.0, 1.0, 0.0, 0.0, 1.0],
+                ],
+            ],
+            [
+                [
+                    [1.0, 1.0, 1.0, 1.0, 0.0],
+                    [1.0, 1.0, 0.0, 0.0, 0.0],
+                    [0.0, 1.0, 0.0, 0.0, 0.0],
+                    [0.0, 1.0, 0.0, 0.0, 0.0],
+                    [1.0, 1.0, 1.0, 1.0, 0.0],
+                ],
+                [
+                    [0.0, 0.0, 0.0, 0.0, 1.0],
+                    [0.0, 0.0, 1.0, 1.0, 1.0],
+                    [0.0, 0.0, 1.0, 1.0, 0.0],
+                    [0.0, 0.0, 1.0, 0.0, 0.0],
+                    [0.0, 0.0, 0.0, 0.0, 0.0],
+                ],
+                [
+                    [0.0, 0.0, 0.0, 0.0, 0.0],
+                    [0.0, 0.0, 0.0, 0.0, 0.0],
+                    [0.0, 0.0, 0.0, 0.0, 1.0],
+                    [0.0, 0.0, 0.0, 1.0, 1.0],
+                    [0.0, 0.0, 0.0, 0.0, 0.0],
+                ],
+            ],
+        ]
+    ),
 ]
 
 TEST_CASE_12 = [
-    "all_0_batch_2",
-    {"independent": False, "applied_values": [1], "background": 3},
+    "onehot_independent_batch_2_apply_label_1_connect_2",
+    {"independent": True, "applied_labels": [1], "connectivity": 2},
+    grid_3,
+    torch.tensor(
+        [
+            [
+                [
+                    [1.0, 1.0, 0.0, 1.0, 1.0],
+                    [1.0, 0.0, 0.0, 0.0, 0.0],
+                    [0.0, 0.0, 0.0, 1.0, 1.0],
+                    [0.0, 0.0, 1.0, 0.0, 1.0],
+                    [0.0, 0.0, 1.0, 1.0, 0.0],
+                ],
+                [
+                    [0.0, 0.0, 1.0, 0.0, 0.0],
+                    [0.0, 0.0, 1.0, 1.0, 1.0],
+                    [0.0, 0.0, 1.0, 0.0, 0.0],
+                    [0.0, 0.0, 0.0, 1.0, 0.0],
+                    [0.0, 0.0, 0.0, 0.0, 0.0],
+                ],
+                [
+                    [0.0, 0.0, 0.0, 0.0, 0.0],
+                    [0.0, 1.0, 0.0, 0.0, 0.0],
+                    [0.0, 1.0, 0.0, 0.0, 0.0],
+                    [0.0, 1.0, 0.0, 0.0, 0.0],
+                    [1.0, 1.0, 0.0, 0.0, 1.0],
+                ],
+            ],
+            [
+                [
+                    [1.0, 1.0, 1.0, 1.0, 0.0],
+                    [1.0, 1.0, 0.0, 0.0, 0.0],
+                    [0.0, 1.0, 0.0, 0.0, 0.0],
+                    [0.0, 1.0, 0.0, 0.0, 0.0],
+                    [1.0, 1.0, 1.0, 1.0, 0.0],
+                ],
+                [
+                    [0.0, 0.0, 0.0, 0.0, 1.0],
+                    [0.0, 0.0, 1.0, 1.0, 1.0],
+                    [0.0, 0.0, 1.0, 1.0, 0.0],
+                    [0.0, 0.0, 1.0, 0.0, 0.0],
+                    [0.0, 0.0, 0.0, 0.0, 0.0],
+                ],
+                [
+                    [0.0, 0.0, 0.0, 0.0, 0.0],
+                    [0.0, 0.0, 0.0, 0.0, 0.0],
+                    [0.0, 0.0, 0.0, 0.0, 1.0],
+                    [0.0, 0.0, 0.0, 1.0, 1.0],
+                    [0.0, 0.0, 0.0, 0.0, 0.0],
+                ],
+            ],
+        ]
+    ),
+]
+
+TEST_CASE_13 = [
+    "onehot_independent_batch_2_apply_label_1_2_connect_2",
+    {"independent": True, "applied_labels": [1, 2], "connectivity": 2},
+    grid_3,
+    torch.tensor(
+        [
+            [
+                [
+                    [1.0, 1.0, 0.0, 1.0, 1.0],
+                    [1.0, 0.0, 0.0, 0.0, 0.0],
+                    [0.0, 0.0, 0.0, 1.0, 1.0],
+                    [0.0, 0.0, 1.0, 0.0, 1.0],
+                    [0.0, 0.0, 1.0, 1.0, 0.0],
+                ],
+                [
+                    [0.0, 0.0, 1.0, 0.0, 0.0],
+                    [0.0, 0.0, 1.0, 1.0, 1.0],
+                    [0.0, 0.0, 1.0, 0.0, 0.0],
+                    [0.0, 0.0, 0.0, 1.0, 0.0],
+                    [0.0, 0.0, 0.0, 0.0, 0.0],
+                ],
+                [
+                    [0.0, 0.0, 0.0, 0.0, 0.0],
+                    [0.0, 1.0, 0.0, 0.0, 0.0],
+                    [0.0, 1.0, 0.0, 0.0, 0.0],
+                    [0.0, 1.0, 0.0, 0.0, 0.0],
+                    [1.0, 1.0, 0.0, 0.0, 0.0],
+                ],
+            ],
+            [
+                [
+                    [1.0, 1.0, 1.0, 1.0, 0.0],
+                    [1.0, 1.0, 0.0, 0.0, 0.0],
+                    [0.0, 1.0, 0.0, 0.0, 0.0],
+                    [0.0, 1.0, 0.0, 0.0, 0.0],
+                    [1.0, 1.0, 1.0, 1.0, 0.0],
+                ],
+                [
+                    [0.0, 0.0, 0.0, 0.0, 1.0],
+                    [0.0, 0.0, 1.0, 1.0, 1.0],
+                    [0.0, 0.0, 1.0, 1.0, 0.0],
+                    [0.0, 0.0, 1.0, 0.0, 0.0],
+                    [0.0, 0.0, 0.0, 0.0, 0.0],
+                ],
+                [
+                    [0.0, 0.0, 0.0, 0.0, 0.0],
+                    [0.0, 0.0, 0.0, 0.0, 0.0],
+                    [0.0, 0.0, 0.0, 0.0, 1.0],
+                    [0.0, 0.0, 0.0, 1.0, 1.0],
+                    [0.0, 0.0, 0.0, 0.0, 0.0],
+                ],
+            ],
+        ]
+    ),
+]
+
+TEST_CASE_14 = [
+    "onehot_dependent_batch_2_apply_label_1_2_connect_2",
+    {"independent": False, "applied_labels": [1, 2], "connectivity": 2},
+    grid_3,
     torch.tensor(
         [
-            [[[0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0]]],
-            [[[1, 1, 1, 1, 1], [0, 0, 0, 0, 0], [0, 0, 1, 1, 1], [0, 0, 1, 0, 0], [0, 0, 0, 0, 0]]],
+            [
+                [
+                    [1.0, 1.0, 0.0, 1.0, 1.0],
+                    [1.0, 0.0, 0.0, 0.0, 0.0],
+                    [0.0, 0.0, 0.0, 1.0, 1.0],
+                    [0.0, 0.0, 1.0, 0.0, 1.0],
+                    [0.0, 0.0, 1.0, 1.0, 0.0],
+                ],
+                [
+                    [0.0, 0.0, 1.0, 0.0, 0.0],
+                    [0.0, 0.0, 1.0, 1.0, 1.0],
+                    [1.0, 0.0, 1.0, 0.0, 0.0],
+                    [1.0, 0.0, 0.0, 1.0, 0.0],
+                    [0.0, 0.0, 0.0, 0.0, 0.0],
+                ],
+                [
+                    [0.0, 0.0, 0.0, 0.0, 0.0],
+                    [0.0, 1.0, 0.0, 0.0, 0.0],
+                    [0.0, 1.0, 0.0, 0.0, 0.0],
+                    [0.0, 1.0, 0.0, 0.0, 0.0],
+                    [1.0, 1.0, 0.0, 0.0, 1.0],
+                ],
+            ],
+            [
+                [
+                    [1.0, 1.0, 1.0, 1.0, 0.0],
+                    [1.0, 1.0, 0.0, 0.0, 0.0],
+                    [0.0, 1.0, 0.0, 0.0, 0.0],
+                    [0.0, 1.0, 0.0, 0.0, 0.0],
+                    [1.0, 1.0, 1.0, 1.0, 0.0],
+                ],
+                [
+                    [0.0, 0.0, 0.0, 0.0, 1.0],
+                    [0.0, 0.0, 1.0, 1.0, 1.0],
+                    [0.0, 0.0, 1.0, 1.0, 0.0],
+                    [0.0, 0.0, 1.0, 0.0, 0.0],
+                    [0.0, 0.0, 0.0, 0.0, 1.0],
+                ],
+                [
+                    [0.0, 0.0, 0.0, 0.0, 0.0],
+                    [0.0, 0.0, 0.0, 0.0, 0.0],
+                    [0.0, 0.0, 0.0, 0.0, 1.0],
+                    [0.0, 0.0, 0.0, 1.0, 1.0],
+                    [0.0, 0.0, 0.0, 0.0, 0.0],
+                ],
+            ],
         ]
     ),
+]
+
+TEST_CASE_15 = [
+    "onehot_dependent_batch_2_apply_label_1_2_connect_1",
+    {"independent": False, "applied_labels": [1, 2], "connectivity": 1},
+    grid_3,
     torch.tensor(
         [
-            [[[0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0]]],
-            [[[1, 1, 1, 1, 1], [0, 0, 0, 0, 0], [0, 0, 3, 3, 3], [0, 0, 3, 0, 0], [0, 0, 0, 0, 0]]],
+            [
+                [
+                    [1.0, 1.0, 0.0, 1.0, 1.0],
+                    [1.0, 0.0, 0.0, 0.0, 0.0],
+                    [0.0, 0.0, 0.0, 1.0, 1.0],
+                    [0.0, 0.0, 1.0, 0.0, 1.0],
+                    [0.0, 0.0, 1.0, 1.0, 0.0],
+                ],
+                [
+                    [0.0, 0.0, 1.0, 0.0, 0.0],
+                    [0.0, 0.0, 1.0, 1.0, 1.0],
+                    [1.0, 0.0, 1.0, 0.0, 0.0],
+                    [1.0, 0.0, 0.0, 0.0, 0.0],
+                    [0.0, 0.0, 0.0, 0.0, 0.0],
+                ],
+                [
+                    [0.0, 0.0, 0.0, 0.0, 0.0],
+                    [0.0, 1.0, 0.0, 0.0, 0.0],
+                    [0.0, 1.0, 0.0, 0.0, 0.0],
+                    [0.0, 1.0, 0.0, 0.0, 0.0],
+                    [1.0, 1.0, 0.0, 0.0, 0.0],
+                ],
+            ],
+            [
+                [
+                    [1.0, 1.0, 1.0, 1.0, 0.0],
+                    [1.0, 1.0, 0.0, 0.0, 0.0],
+                    [0.0, 1.0, 0.0, 0.0, 0.0],
+                    [0.0, 1.0, 0.0, 0.0, 0.0],
+                    [1.0, 1.0, 1.0, 1.0, 0.0],
+                ],
+                [
+                    [0.0, 0.0, 0.0, 0.0, 1.0],
+                    [0.0, 0.0, 1.0, 1.0, 1.0],
+                    [0.0, 0.0, 1.0, 1.0, 0.0],
+                    [0.0, 0.0, 1.0, 0.0, 0.0],
+                    [0.0, 0.0, 0.0, 0.0, 1.0],
+                ],
+                [
+                    [0.0, 0.0, 0.0, 0.0, 0.0],
+                    [0.0, 0.0, 0.0, 0.0, 0.0],
+                    [0.0, 0.0, 0.0, 0.0, 1.0],
+                    [0.0, 0.0, 0.0, 1.0, 1.0],
+                    [0.0, 0.0, 0.0, 0.0, 0.0],
+                ],
+            ],
         ]
     ),
 ]
@@ -126,6 +433,28 @@
     TEST_CASE_10,
     TEST_CASE_11,
     TEST_CASE_12,
+    TEST_CASE_13,
+    TEST_CASE_14,
+    TEST_CASE_15,
+]
+
+ITEST_CASE_1 = [
+    "no_applied_labels_for_single_channel",
+    {"independent": False},
+    grid_1,
+    TypeError,
+]
+
+ITEST_CASE_2 = [
+    "no_applied_labels_for_multi_channel",
+    {"independent": False},
+    grid_3,
+    TypeError,
+]
+
+INVALID_CASES = [
+    ITEST_CASE_1,
+    ITEST_CASE_2,
 ]
 
 
@@ -140,6 +469,15 @@ def test_correct_results(self, _, args, tensor, expected):
             result = converter(tensor.clone())
             assert torch.allclose(result, expected)
 
+    @parameterized.expand(INVALID_CASES)
+    def test_raise_exception(self, _, args, tensor, expected_error):
+        with self.assertRaises(expected_error):
+            converter = KeepLargestConnectedComponent(**args)
+            if torch.cuda.is_available():
+                _ = converter(tensor.clone().cuda())
+            else:
+                _ = converter(tensor.clone())
+
 
 if __name__ == "__main__":
     unittest.main()
diff --git a/tests/test_keep_largest_connected_componentd.py b/tests/test_keep_largest_connected_componentd.py
--- a/tests/test_keep_largest_connected_componentd.py
+++ b/tests/test_keep_largest_connected_componentd.py
@@ -22,106 +22,412 @@
 grid_2 = {
     "img": torch.tensor([[[[0, 0, 0, 0, 1], [0, 0, 1, 1, 1], [1, 0, 1, 1, 2], [1, 0, 1, 2, 2], [0, 0, 0, 0, 1]]]])
 }
+grid_3 = {
+    "img": torch.tensor(
+        [
+            [
+                [
+                    [1.0, 1.0, 0.0, 1.0, 1.0],
+                    [1.0, 0.0, 0.0, 0.0, 0.0],
+                    [0.0, 0.0, 0.0, 1.0, 1.0],
+                    [0.0, 0.0, 1.0, 0.0, 1.0],
+                    [0.0, 0.0, 1.0, 1.0, 0.0],
+                ],
+                [
+                    [0.0, 0.0, 1.0, 0.0, 0.0],
+                    [0.0, 0.0, 1.0, 1.0, 1.0],
+                    [1.0, 0.0, 1.0, 0.0, 0.0],
+                    [1.0, 0.0, 0.0, 1.0, 0.0],
+                    [0.0, 0.0, 0.0, 0.0, 0.0],
+                ],
+                [
+                    [0.0, 0.0, 0.0, 0.0, 0.0],
+                    [0.0, 1.0, 0.0, 0.0, 0.0],
+                    [0.0, 1.0, 0.0, 0.0, 0.0],
+                    [0.0, 1.0, 0.0, 0.0, 0.0],
+                    [1.0, 1.0, 0.0, 0.0, 1.0],
+                ],
+            ],
+            [
+                [
+                    [1.0, 1.0, 1.0, 1.0, 0.0],
+                    [1.0, 1.0, 0.0, 0.0, 0.0],
+                    [0.0, 1.0, 0.0, 0.0, 0.0],
+                    [0.0, 1.0, 0.0, 0.0, 0.0],
+                    [1.0, 1.0, 1.0, 1.0, 0.0],
+                ],
+                [
+                    [0.0, 0.0, 0.0, 0.0, 1.0],
+                    [0.0, 0.0, 1.0, 1.0, 1.0],
+                    [1.0, 0.0, 1.0, 1.0, 0.0],
+                    [1.0, 0.0, 1.0, 0.0, 0.0],
+                    [0.0, 0.0, 0.0, 0.0, 1.0],
+                ],
+                [
+                    [0.0, 0.0, 0.0, 0.0, 0.0],
+                    [0.0, 0.0, 0.0, 0.0, 0.0],
+                    [0.0, 0.0, 0.0, 0.0, 1.0],
+                    [0.0, 0.0, 0.0, 1.0, 1.0],
+                    [0.0, 0.0, 0.0, 0.0, 0.0],
+                ],
+            ],
+        ]
+    )
+}
 
 TEST_CASE_1 = [
     "value_1",
-    {"keys": ["img"], "independent": False, "applied_values": [1]},
+    {"keys": ["img"], "independent": False, "applied_labels": 1},
     grid_1,
     torch.tensor([[[[0, 0, 1, 0, 0], [0, 2, 1, 1, 1], [0, 2, 1, 0, 0], [0, 2, 0, 1, 0], [2, 2, 0, 0, 2]]]]),
 ]
 
 TEST_CASE_2 = [
     "value_2",
-    {"keys": ["img"], "independent": False, "applied_values": [2]},
+    {"keys": ["img"], "independent": False, "applied_labels": [2]},
     grid_1,
     torch.tensor([[[[0, 0, 1, 0, 0], [0, 2, 1, 1, 1], [1, 2, 1, 0, 0], [1, 2, 0, 1, 0], [2, 2, 0, 0, 0]]]]),
 ]
 
 TEST_CASE_3 = [
     "independent_value_1_2",
-    {"keys": ["img"], "independent": True, "applied_values": [1, 2]},
+    {"keys": ["img"], "independent": True, "applied_labels": [1, 2]},
     grid_1,
     torch.tensor([[[[0, 0, 1, 0, 0], [0, 2, 1, 1, 1], [0, 2, 1, 0, 0], [0, 2, 0, 1, 0], [2, 2, 0, 0, 0]]]]),
 ]
 
 TEST_CASE_4 = [
     "dependent_value_1_2",
-    {"keys": ["img"], "independent": False, "applied_values": [1, 2]},
+    {"keys": ["img"], "independent": False, "applied_labels": [1, 2]},
     grid_1,
     torch.tensor([[[[0, 0, 1, 0, 0], [0, 2, 1, 1, 1], [1, 2, 1, 0, 0], [1, 2, 0, 1, 0], [2, 2, 0, 0, 2]]]]),
 ]
 
 TEST_CASE_5 = [
     "value_1",
-    {"keys": ["img"], "independent": True, "applied_values": [1]},
+    {"keys": ["img"], "independent": True, "applied_labels": [1]},
     grid_2,
     torch.tensor([[[[0, 0, 0, 0, 1], [0, 0, 1, 1, 1], [0, 0, 1, 1, 2], [0, 0, 1, 2, 2], [0, 0, 0, 0, 0]]]]),
 ]
 
 TEST_CASE_6 = [
     "independent_value_1_2",
-    {"keys": ["img"], "independent": True, "applied_values": [1, 2]},
+    {"keys": ["img"], "independent": True, "applied_labels": [1, 2]},
     grid_2,
     torch.tensor([[[[0, 0, 0, 0, 1], [0, 0, 1, 1, 1], [0, 0, 1, 1, 2], [0, 0, 1, 2, 2], [0, 0, 0, 0, 0]]]]),
 ]
 
 TEST_CASE_7 = [
     "dependent_value_1_2",
-    {"keys": ["img"], "independent": False, "applied_values": [1, 2]},
+    {"keys": ["img"], "independent": False, "applied_labels": [1, 2]},
     grid_2,
     torch.tensor([[[[0, 0, 0, 0, 1], [0, 0, 1, 1, 1], [0, 0, 1, 1, 2], [0, 0, 1, 2, 2], [0, 0, 0, 0, 1]]]]),
 ]
 
 TEST_CASE_8 = [
     "value_1_connect_1",
-    {"keys": ["img"], "independent": False, "applied_values": [1], "connectivity": 1},
+    {"keys": ["img"], "independent": False, "applied_labels": [1], "connectivity": 1},
     grid_1,
     torch.tensor([[[[0, 0, 1, 0, 0], [0, 2, 1, 1, 1], [0, 2, 1, 0, 0], [0, 2, 0, 0, 0], [2, 2, 0, 0, 2]]]]),
 ]
 
 TEST_CASE_9 = [
     "independent_value_1_2_connect_1",
-    {"keys": ["img"], "independent": True, "applied_values": [1, 2], "connectivity": 1},
+    {"keys": ["img"], "independent": True, "applied_labels": [1, 2], "connectivity": 1},
     grid_1,
     torch.tensor([[[[0, 0, 1, 0, 0], [0, 2, 1, 1, 1], [0, 2, 1, 0, 0], [0, 2, 0, 0, 0], [2, 2, 0, 0, 0]]]]),
 ]
 
 TEST_CASE_10 = [
     "dependent_value_1_2_connect_1",
-    {"keys": ["img"], "independent": False, "applied_values": [1, 2], "connectivity": 1},
+    {"keys": ["img"], "independent": False, "applied_labels": [1, 2], "connectivity": 1},
     grid_1,
     torch.tensor([[[[0, 0, 1, 0, 0], [0, 2, 1, 1, 1], [1, 2, 1, 0, 0], [1, 2, 0, 0, 0], [2, 2, 0, 0, 0]]]]),
 ]
 
 TEST_CASE_11 = [
-    "value_0_background_3",
-    {"keys": ["img"], "independent": False, "applied_values": [0], "background": 3},
-    grid_1,
-    torch.tensor([[[[3, 3, 1, 3, 3], [3, 2, 1, 1, 1], [1, 2, 1, 0, 0], [1, 2, 0, 1, 0], [2, 2, 0, 0, 2]]]]),
+    "onehot_independent_batch_2_apply_label_1_connect_1",
+    {"keys": ["img"], "independent": True, "applied_labels": [1], "connectivity": 1},
+    grid_3,
+    torch.tensor(
+        [
+            [
+                [
+                    [1.0, 1.0, 0.0, 1.0, 1.0],
+                    [1.0, 0.0, 0.0, 0.0, 0.0],
+                    [0.0, 0.0, 0.0, 1.0, 1.0],
+                    [0.0, 0.0, 1.0, 0.0, 1.0],
+                    [0.0, 0.0, 1.0, 1.0, 0.0],
+                ],
+                [
+                    [0.0, 0.0, 1.0, 0.0, 0.0],
+                    [0.0, 0.0, 1.0, 1.0, 1.0],
+                    [0.0, 0.0, 1.0, 0.0, 0.0],
+                    [0.0, 0.0, 0.0, 0.0, 0.0],
+                    [0.0, 0.0, 0.0, 0.0, 0.0],
+                ],
+                [
+                    [0.0, 0.0, 0.0, 0.0, 0.0],
+                    [0.0, 1.0, 0.0, 0.0, 0.0],
+                    [0.0, 1.0, 0.0, 0.0, 0.0],
+                    [0.0, 1.0, 0.0, 0.0, 0.0],
+                    [1.0, 1.0, 0.0, 0.0, 1.0],
+                ],
+            ],
+            [
+                [
+                    [1.0, 1.0, 1.0, 1.0, 0.0],
+                    [1.0, 1.0, 0.0, 0.0, 0.0],
+                    [0.0, 1.0, 0.0, 0.0, 0.0],
+                    [0.0, 1.0, 0.0, 0.0, 0.0],
+                    [1.0, 1.0, 1.0, 1.0, 0.0],
+                ],
+                [
+                    [0.0, 0.0, 0.0, 0.0, 1.0],
+                    [0.0, 0.0, 1.0, 1.0, 1.0],
+                    [0.0, 0.0, 1.0, 1.0, 0.0],
+                    [0.0, 0.0, 1.0, 0.0, 0.0],
+                    [0.0, 0.0, 0.0, 0.0, 0.0],
+                ],
+                [
+                    [0.0, 0.0, 0.0, 0.0, 0.0],
+                    [0.0, 0.0, 0.0, 0.0, 0.0],
+                    [0.0, 0.0, 0.0, 0.0, 1.0],
+                    [0.0, 0.0, 0.0, 1.0, 1.0],
+                    [0.0, 0.0, 0.0, 0.0, 0.0],
+                ],
+            ],
+        ]
+    ),
 ]
 
 TEST_CASE_12 = [
-    "all_0_batch_2",
-    {"keys": ["img"], "independent": False, "applied_values": [1], "background": 3},
-    {
-        "img": torch.tensor(
-            [
-                [[[0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0]]],
-                [[[1, 1, 1, 1, 1], [0, 0, 0, 0, 0], [0, 0, 1, 1, 1], [0, 0, 1, 0, 0], [0, 0, 0, 0, 0]]],
-            ]
-        )
-    },
+    "onehot_independent_batch_2_apply_label_1_connect_2",
+    {"keys": ["img"], "independent": True, "applied_labels": [1], "connectivity": 2},
+    grid_3,
     torch.tensor(
         [
-            [[[0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0]]],
-            [[[1, 1, 1, 1, 1], [0, 0, 0, 0, 0], [0, 0, 3, 3, 3], [0, 0, 3, 0, 0], [0, 0, 0, 0, 0]]],
+            [
+                [
+                    [1.0, 1.0, 0.0, 1.0, 1.0],
+                    [1.0, 0.0, 0.0, 0.0, 0.0],
+                    [0.0, 0.0, 0.0, 1.0, 1.0],
+                    [0.0, 0.0, 1.0, 0.0, 1.0],
+                    [0.0, 0.0, 1.0, 1.0, 0.0],
+                ],
+                [
+                    [0.0, 0.0, 1.0, 0.0, 0.0],
+                    [0.0, 0.0, 1.0, 1.0, 1.0],
+                    [0.0, 0.0, 1.0, 0.0, 0.0],
+                    [0.0, 0.0, 0.0, 1.0, 0.0],
+                    [0.0, 0.0, 0.0, 0.0, 0.0],
+                ],
+                [
+                    [0.0, 0.0, 0.0, 0.0, 0.0],
+                    [0.0, 1.0, 0.0, 0.0, 0.0],
+                    [0.0, 1.0, 0.0, 0.0, 0.0],
+                    [0.0, 1.0, 0.0, 0.0, 0.0],
+                    [1.0, 1.0, 0.0, 0.0, 1.0],
+                ],
+            ],
+            [
+                [
+                    [1.0, 1.0, 1.0, 1.0, 0.0],
+                    [1.0, 1.0, 0.0, 0.0, 0.0],
+                    [0.0, 1.0, 0.0, 0.0, 0.0],
+                    [0.0, 1.0, 0.0, 0.0, 0.0],
+                    [1.0, 1.0, 1.0, 1.0, 0.0],
+                ],
+                [
+                    [0.0, 0.0, 0.0, 0.0, 1.0],
+                    [0.0, 0.0, 1.0, 1.0, 1.0],
+                    [0.0, 0.0, 1.0, 1.0, 0.0],
+                    [0.0, 0.0, 1.0, 0.0, 0.0],
+                    [0.0, 0.0, 0.0, 0.0, 0.0],
+                ],
+                [
+                    [0.0, 0.0, 0.0, 0.0, 0.0],
+                    [0.0, 0.0, 0.0, 0.0, 0.0],
+                    [0.0, 0.0, 0.0, 0.0, 1.0],
+                    [0.0, 0.0, 0.0, 1.0, 1.0],
+                    [0.0, 0.0, 0.0, 0.0, 0.0],
+                ],
+            ],
         ]
     ),
 ]
 
 TEST_CASE_13 = [
+    "onehot_independent_batch_2_apply_label_1_2_connect_2",
+    {"keys": ["img"], "independent": True, "applied_labels": [1, 2], "connectivity": 2},
+    grid_3,
+    torch.tensor(
+        [
+            [
+                [
+                    [1.0, 1.0, 0.0, 1.0, 1.0],
+                    [1.0, 0.0, 0.0, 0.0, 0.0],
+                    [0.0, 0.0, 0.0, 1.0, 1.0],
+                    [0.0, 0.0, 1.0, 0.0, 1.0],
+                    [0.0, 0.0, 1.0, 1.0, 0.0],
+                ],
+                [
+                    [0.0, 0.0, 1.0, 0.0, 0.0],
+                    [0.0, 0.0, 1.0, 1.0, 1.0],
+                    [0.0, 0.0, 1.0, 0.0, 0.0],
+                    [0.0, 0.0, 0.0, 1.0, 0.0],
+                    [0.0, 0.0, 0.0, 0.0, 0.0],
+                ],
+                [
+                    [0.0, 0.0, 0.0, 0.0, 0.0],
+                    [0.0, 1.0, 0.0, 0.0, 0.0],
+                    [0.0, 1.0, 0.0, 0.0, 0.0],
+                    [0.0, 1.0, 0.0, 0.0, 0.0],
+                    [1.0, 1.0, 0.0, 0.0, 0.0],
+                ],
+            ],
+            [
+                [
+                    [1.0, 1.0, 1.0, 1.0, 0.0],
+                    [1.0, 1.0, 0.0, 0.0, 0.0],
+                    [0.0, 1.0, 0.0, 0.0, 0.0],
+                    [0.0, 1.0, 0.0, 0.0, 0.0],
+                    [1.0, 1.0, 1.0, 1.0, 0.0],
+                ],
+                [
+                    [0.0, 0.0, 0.0, 0.0, 1.0],
+                    [0.0, 0.0, 1.0, 1.0, 1.0],
+                    [0.0, 0.0, 1.0, 1.0, 0.0],
+                    [0.0, 0.0, 1.0, 0.0, 0.0],
+                    [0.0, 0.0, 0.0, 0.0, 0.0],
+                ],
+                [
+                    [0.0, 0.0, 0.0, 0.0, 0.0],
+                    [0.0, 0.0, 0.0, 0.0, 0.0],
+                    [0.0, 0.0, 0.0, 0.0, 1.0],
+                    [0.0, 0.0, 0.0, 1.0, 1.0],
+                    [0.0, 0.0, 0.0, 0.0, 0.0],
+                ],
+            ],
+        ]
+    ),
+]
+
+TEST_CASE_14 = [
+    "onehot_dependent_batch_2_apply_label_1_2_connect_2",
+    {"keys": ["img"], "independent": False, "applied_labels": [1, 2], "connectivity": 2},
+    grid_3,
+    torch.tensor(
+        [
+            [
+                [
+                    [1.0, 1.0, 0.0, 1.0, 1.0],
+                    [1.0, 0.0, 0.0, 0.0, 0.0],
+                    [0.0, 0.0, 0.0, 1.0, 1.0],
+                    [0.0, 0.0, 1.0, 0.0, 1.0],
+                    [0.0, 0.0, 1.0, 1.0, 0.0],
+                ],
+                [
+                    [0.0, 0.0, 1.0, 0.0, 0.0],
+                    [0.0, 0.0, 1.0, 1.0, 1.0],
+                    [1.0, 0.0, 1.0, 0.0, 0.0],
+                    [1.0, 0.0, 0.0, 1.0, 0.0],
+                    [0.0, 0.0, 0.0, 0.0, 0.0],
+                ],
+                [
+                    [0.0, 0.0, 0.0, 0.0, 0.0],
+                    [0.0, 1.0, 0.0, 0.0, 0.0],
+                    [0.0, 1.0, 0.0, 0.0, 0.0],
+                    [0.0, 1.0, 0.0, 0.0, 0.0],
+                    [1.0, 1.0, 0.0, 0.0, 1.0],
+                ],
+            ],
+            [
+                [
+                    [1.0, 1.0, 1.0, 1.0, 0.0],
+                    [1.0, 1.0, 0.0, 0.0, 0.0],
+                    [0.0, 1.0, 0.0, 0.0, 0.0],
+                    [0.0, 1.0, 0.0, 0.0, 0.0],
+                    [1.0, 1.0, 1.0, 1.0, 0.0],
+                ],
+                [
+                    [0.0, 0.0, 0.0, 0.0, 1.0],
+                    [0.0, 0.0, 1.0, 1.0, 1.0],
+                    [0.0, 0.0, 1.0, 1.0, 0.0],
+                    [0.0, 0.0, 1.0, 0.0, 0.0],
+                    [0.0, 0.0, 0.0, 0.0, 1.0],
+                ],
+                [
+                    [0.0, 0.0, 0.0, 0.0, 0.0],
+                    [0.0, 0.0, 0.0, 0.0, 0.0],
+                    [0.0, 0.0, 0.0, 0.0, 1.0],
+                    [0.0, 0.0, 0.0, 1.0, 1.0],
+                    [0.0, 0.0, 0.0, 0.0, 0.0],
+                ],
+            ],
+        ]
+    ),
+]
+
+TEST_CASE_15 = [
+    "onehot_dependent_batch_2_apply_label_1_2_connect_1",
+    {"keys": ["img"], "independent": False, "applied_labels": [1, 2], "connectivity": 1},
+    grid_3,
+    torch.tensor(
+        [
+            [
+                [
+                    [1.0, 1.0, 0.0, 1.0, 1.0],
+                    [1.0, 0.0, 0.0, 0.0, 0.0],
+                    [0.0, 0.0, 0.0, 1.0, 1.0],
+                    [0.0, 0.0, 1.0, 0.0, 1.0],
+                    [0.0, 0.0, 1.0, 1.0, 0.0],
+                ],
+                [
+                    [0.0, 0.0, 1.0, 0.0, 0.0],
+                    [0.0, 0.0, 1.0, 1.0, 1.0],
+                    [1.0, 0.0, 1.0, 0.0, 0.0],
+                    [1.0, 0.0, 0.0, 0.0, 0.0],
+                    [0.0, 0.0, 0.0, 0.0, 0.0],
+                ],
+                [
+                    [0.0, 0.0, 0.0, 0.0, 0.0],
+                    [0.0, 1.0, 0.0, 0.0, 0.0],
+                    [0.0, 1.0, 0.0, 0.0, 0.0],
+                    [0.0, 1.0, 0.0, 0.0, 0.0],
+                    [1.0, 1.0, 0.0, 0.0, 0.0],
+                ],
+            ],
+            [
+                [
+                    [1.0, 1.0, 1.0, 1.0, 0.0],
+                    [1.0, 1.0, 0.0, 0.0, 0.0],
+                    [0.0, 1.0, 0.0, 0.0, 0.0],
+                    [0.0, 1.0, 0.0, 0.0, 0.0],
+                    [1.0, 1.0, 1.0, 1.0, 0.0],
+                ],
+                [
+                    [0.0, 0.0, 0.0, 0.0, 1.0],
+                    [0.0, 0.0, 1.0, 1.0, 1.0],
+                    [0.0, 0.0, 1.0, 1.0, 0.0],
+                    [0.0, 0.0, 1.0, 0.0, 0.0],
+                    [0.0, 0.0, 0.0, 0.0, 1.0],
+                ],
+                [
+                    [0.0, 0.0, 0.0, 0.0, 0.0],
+                    [0.0, 0.0, 0.0, 0.0, 0.0],
+                    [0.0, 0.0, 0.0, 0.0, 1.0],
+                    [0.0, 0.0, 0.0, 1.0, 1.0],
+                    [0.0, 0.0, 0.0, 0.0, 0.0],
+                ],
+            ],
+        ]
+    ),
+]
+
+TEST_CASE_18 = [
     "none_postfix",
-    {"keys": ["img"], "output_postfix": None, "independent": False, "applied_values": [1]},
+    {"keys": ["img"], "output_postfix": None, "independent": False, "applied_labels": [1]},
     grid_1,
     torch.tensor([[[[0, 0, 1, 0, 0], [0, 2, 1, 1, 1], [0, 2, 1, 0, 0], [0, 2, 0, 1, 0], [2, 2, 0, 0, 2]]]]),
 ]
@@ -139,6 +445,28 @@
     TEST_CASE_10,
     TEST_CASE_11,
     TEST_CASE_12,
+    TEST_CASE_13,
+    TEST_CASE_14,
+    TEST_CASE_15,
+]
+
+ITEST_CASE_1 = [
+    "no_applied_labels_for_single_channel",
+    {"keys": ["img"], "independent": False},
+    grid_1,
+    TypeError,
+]
+
+ITEST_CASE_2 = [
+    "no_applied_labels_for_multi_channel",
+    {"keys": ["img"], "independent": False},
+    grid_3,
+    TypeError,
+]
+
+INVALID_CASES = [
+    ITEST_CASE_1,
+    ITEST_CASE_2,
 ]
 
 
@@ -154,7 +482,15 @@ def test_correct_results(self, _, args, input_dict, expected):
             result = converter(input_dict)
             torch.allclose(result["img_largestcc"], expected)
 
-    @parameterized.expand([TEST_CASE_13])
+    @parameterized.expand(INVALID_CASES)
+    def test_raise_exception(self, _, args, input_dict, expected_error):
+        with self.assertRaises(expected_error):
+            converter = KeepLargestConnectedComponentd(**args)
+            if torch.cuda.is_available():
+                input_dict["img"] = input_dict["img"].cuda()
+            _ = converter(input_dict)
+
+    @parameterized.expand([TEST_CASE_18])
     def test_none_postfix(self, _, args, input_dict, expected):
         converter = KeepLargestConnectedComponentd(**args)
         input_dict["img"] = input_dict["img"].cpu()