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

Class RemoveSmallObjects

monai/transforms/post/array.py:365–450  ·  view source on GitHub ↗

Use `skimage.morphology.remove_small_objects` to remove small objects from images. See: https://scikit-image.org/docs/dev/api/skimage.morphology.html#remove-small-objects. Data should be one-hotted. Args: min_size: objects smaller than this size (in number of voxels; or su

Source from the content-addressed store, hash-verified

363
364
365class RemoveSmallObjects(Transform):
366 """
367 Use `skimage.morphology.remove_small_objects` to remove small objects from images.
368 See: https://scikit-image.org/docs/dev/api/skimage.morphology.html#remove-small-objects.
369
370 Data should be one-hotted.
371
372 Args:
373 min_size: objects smaller than this size (in number of voxels; or surface area/volume value
374 in whatever units your image is if by_measure is True) are removed.
375 connectivity: Maximum number of orthogonal hops to consider a pixel/voxel as a neighbor.
376 Accepted values are ranging from 1 to input.ndim. If ``None``, a full
377 connectivity of ``input.ndim`` is used. For more details refer to linked scikit-image
378 documentation.
379 independent_channels: Whether or not to consider channels as independent. If true, then
380 conjoining islands from different labels will be removed if they are below the threshold.
381 If false, the overall size islands made from all non-background voxels will be used.
382 by_measure: Whether the specified min_size is in number of voxels. if this is True then min_size
383 represents a surface area or volume value of whatever units your image is in (mm^3, cm^2, etc.)
384 default is False. e.g. if min_size is 3, by_measure is True and the units of your data is mm,
385 objects smaller than 3mm^3 are removed.
386 pixdim: the pixdim of the input image. if a single number, this is used for all axes.
387 If a sequence of numbers, the length of the sequence must be equal to the image dimensions.
388
389 Example::
390
391 .. code-block:: python
392
393 from monai.transforms import RemoveSmallObjects, Spacing, Compose
394 from monai.data import MetaTensor
395
396 data1 = torch.tensor([[[0, 0, 0, 0, 0], [0, 1, 1, 0, 1], [0, 0, 0, 1, 1]]])
397 affine = torch.as_tensor([[2,0,0,0],
398 [0,1,0,0],
399 [0,0,1,0],
400 [0,0,0,1]], dtype=torch.float64)
401 data2 = MetaTensor(data1, affine=affine)
402
403 # remove objects smaller than 3mm^3, input is MetaTensor
404 trans = RemoveSmallObjects(min_size=3, by_measure=True)
405 out = trans(data2)
406 # remove objects smaller than 3mm^3, input is not MetaTensor
407 trans = RemoveSmallObjects(min_size=3, by_measure=True, pixdim=(2, 1, 1))
408 out = trans(data1)
409
410 # remove objects smaller than 3 (in pixel)
411 trans = RemoveSmallObjects(min_size=3)
412 out = trans(data2)
413
414 # If the affine of the data is not identity, you can also add Spacing before.
415 trans = Compose([
416 Spacing(pixdim=(1, 1, 1)),
417 RemoveSmallObjects(min_size=3)
418 ])
419
420 """
421
422 backend = [TransformBackends.NUMPY]

Callers 5

__init__Method · 0.90
__init__Method · 0.90
__init__Method · 0.90

Calls

no outgoing calls

Used in the wild real call sites across dependent graphs

searching dependent graphs…