def __init__( self, keys: KeysCollection, applied_labels: Union[Sequence[int], int], independent: bool = True, connectivity: Optional[int] = None, ) -> None: """ Args: keys: keys of the corresponding items to be transformed. See also: :py:class:`monai.transforms.compose.MapTransform` applied_labels: 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 the channel indexes to apply transform. independent: 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. 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__(keys) self.converter = KeepLargestConnectedComponent(applied_labels, independent, connectivity)
def __init__( self, keys: KeysCollection, applied_labels, independent: bool = True, connectivity: Optional[int] = None, output_postfix: str = "largestcc", ): """ Args: keys: keys of the corresponding items to be transformed. See also: :py:class:`monai.transforms.compose.MapTransform` 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. 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. output_postfix: the postfix string to construct keys to store converted data. for example: if the keys of input data is `label`, output_postfix is `largestcc`, the output data keys will be: `label_largestcc`. if set to None, will replace the original data with the same key. """ super().__init__(keys) 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_labels, independent, connectivity)
def __init__( self, keys: KeysCollection, applied_labels: Optional[Union[Sequence[int], int]] = None, is_onehot: Optional[bool] = None, independent: bool = True, connectivity: Optional[int] = None, allow_missing_keys: bool = False, ) -> None: """ Args: keys: keys of the corresponding items to be transformed. See also: :py:class:`monai.transforms.compose.MapTransform` applied_labels: Labels for applying the connected component analysis on. If given, voxels whose value is in this list will be analyzed. If `None`, all non-zero values will be analyzed. is_onehot: if `True`, treat the input data as OneHot format data, otherwise, not OneHot format data. default to None, which treats multi-channel data as OneHot and single channel data as not OneHot. independent: whether to treat ``applied_labels`` as a union of foreground labels. If ``True``, the connected component analysis will be performed on each foreground label independently and return the intersection of the largest components. If ``False``, the analysis will be performed on the union of foreground labels. default is `True`. 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. for more details: https://scikit-image.org/docs/dev/api/skimage.measure.html#skimage.measure.label. allow_missing_keys: don't raise exception if key is missing. """ super().__init__(keys, allow_missing_keys) self.converter = KeepLargestConnectedComponent( applied_labels=applied_labels, is_onehot=is_onehot, independent=independent, connectivity=connectivity )
def __init__( self, keys, applied_values, independent=True, background=0, connectivity=None, output_postfix="largestcc", ): """ Args: keys (hashable items): 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 (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 (int): Background pixel value. The over-segmented pixels will be set as this value. connectivity (int): 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. output_postfix (str): the postfix string to construct keys to store converted data. for example: if the keys of input data is `label`, output_postfix is `largestcc`, the output data keys will be: `label_largestcc`. if set to None, will replace the original data with the same key. """ super().__init__(keys) 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)