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

Function erode

monai/transforms/utils_morphological_ops.py:26–55  ·  view source on GitHub ↗

Erode 2D/3D binary mask. Args: mask: input 2D/3D binary mask, [N,C,M,N] or [N,C,M,N,P] torch tensor or ndarray. filter_size: erosion filter size, has to be odd numbers, default to be 3. pad_value: the filled value for padding. We need to pad the input before filteri

(mask: NdarrayOrTensor, filter_size: int | Sequence[int] = 3, pad_value: float = 1.0)

Source from the content-addressed store, hash-verified

24
25
26def erode(mask: NdarrayOrTensor, filter_size: int | Sequence[int] = 3, pad_value: float = 1.0) -> NdarrayOrTensor:
27 """
28 Erode 2D/3D binary mask.
29
30 Args:
31 mask: input 2D/3D binary mask, [N,C,M,N] or [N,C,M,N,P] torch tensor or ndarray.
32 filter_size: erosion filter size, has to be odd numbers, default to be 3.
33 pad_value: the filled value for padding. We need to pad the input before filtering
34 to keep the output with the same size as input. Usually use default value
35 and not changed.
36
37 Return:
38 eroded mask, same shape and data type as input.
39
40 Example:
41
42 .. code-block:: python
43
44 # define a naive mask
45 mask = torch.zeros(3,2,3,3,3)
46 mask[:,:,1,1,1] = 1.0
47 filter_size = 3
48 erode_result = erode(mask, filter_size) # expect torch.zeros(3,2,3,3,3)
49 dilate_result = dilate(mask, filter_size) # expect torch.ones(3,2,3,3,3)
50 """
51 mask_t, *_ = convert_data_type(mask, torch.Tensor)
52 res_mask_t = erode_t(mask_t, filter_size=filter_size, pad_value=pad_value)
53 res_mask: NdarrayOrTensor
54 res_mask, *_ = convert_to_dst_type(src=res_mask_t, dst=mask)
55 return res_mask
56
57
58def dilate(mask: NdarrayOrTensor, filter_size: int | Sequence[int] = 3, pad_value: float = 0.0) -> NdarrayOrTensor:

Callers 3

sample_points_from_labelFunction · 0.90
test_shapeMethod · 0.90
test_valueMethod · 0.90

Calls 3

convert_data_typeFunction · 0.90
convert_to_dst_typeFunction · 0.90
erode_tFunction · 0.85

Tested by 2

test_shapeMethod · 0.72
test_valueMethod · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…