MCPcopy Create free account
hub / github.com/Project-MONAI/MONAI / KeepLargestConnectedComponentd

Class KeepLargestConnectedComponentd

monai/transforms/post/dictionary.py:218–270  ·  view source on GitHub ↗

Dictionary-based wrapper of :py:class:`monai.transforms.KeepLargestConnectedComponent`.

Source from the content-addressed store, hash-verified

216
217
218class KeepLargestConnectedComponentd(MapTransform):
219 """
220 Dictionary-based wrapper of :py:class:`monai.transforms.KeepLargestConnectedComponent`.
221 """
222
223 backend = KeepLargestConnectedComponent.backend
224
225 def __init__(
226 self,
227 keys: KeysCollection,
228 applied_labels: Sequence[int] | int | None = None,
229 is_onehot: bool | None = None,
230 independent: bool = True,
231 connectivity: int | None = None,
232 num_components: int = 1,
233 allow_missing_keys: bool = False,
234 ) -> None:
235 """
236 Args:
237 keys: keys of the corresponding items to be transformed.
238 See also: :py:class:`monai.transforms.compose.MapTransform`
239 applied_labels: Labels for applying the connected component analysis on.
240 If given, voxels whose value is in this list will be analyzed.
241 If `None`, all non-zero values will be analyzed.
242 is_onehot: if `True`, treat the input data as OneHot format data, otherwise, not OneHot format data.
243 default to None, which treats multi-channel data as OneHot and single channel data as not OneHot.
244 independent: whether to treat ``applied_labels`` as a union of foreground labels.
245 If ``True``, the connected component analysis will be performed on each foreground label independently
246 and return the intersection of the largest components.
247 If ``False``, the analysis will be performed on the union of foreground labels.
248 default is `True`.
249 connectivity: Maximum number of orthogonal hops to consider a pixel/voxel as a neighbor.
250 Accepted values are ranging from 1 to input.ndim. If ``None``, a full
251 connectivity of ``input.ndim`` is used. for more details:
252 https://scikit-image.org/docs/dev/api/skimage.measure.html#skimage.measure.label.
253 num_components: The number of largest components to preserve.
254 allow_missing_keys: don't raise exception if key is missing.
255
256 """
257 super().__init__(keys, allow_missing_keys)
258 self.converter = KeepLargestConnectedComponent(
259 applied_labels=applied_labels,
260 is_onehot=is_onehot,
261 independent=independent,
262 connectivity=connectivity,
263 num_components=num_components,
264 )
265
266 def __call__(self, data: Mapping[Hashable, NdarrayOrTensor]) -> dict[Hashable, NdarrayOrTensor]:
267 d = dict(data)
268 for key in self.key_iterator(d):
269 d[key] = self.converter(d[key])
270 return d
271
272
273class RemoveSmallObjectsd(MapTransform):

Callers 3

run_training_testFunction · 0.90
run_inference_testFunction · 0.90
test_correct_resultsMethod · 0.90

Calls

no outgoing calls

Tested by 3

run_training_testFunction · 0.72
run_inference_testFunction · 0.72
test_correct_resultsMethod · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…