19
19
from tensorflow_addons .utils import types
20
20
from tensorflow_addons .utils .resource_loader import LazySO
21
21
22
- from typing import Optional
22
+ from typing import Optional , Text
23
23
24
24
_image_so = LazySO ("custom_ops/image/_image_ops.so" )
25
25
26
26
27
27
@tf .function
28
28
def connected_components (
29
- images : types .TensorLike , name : Optional [str ] = None
29
+ images : types .TensorLike , name : Optional [Text ] = None
30
30
) -> tf .Tensor :
31
31
"""Labels the connected components in a batch of images.
32
32
33
33
A component is a set of pixels in a single input image, which are
34
- all adjacent and all have the same non-zero value. The components
35
- using a squared connectivity of one (all True entries are joined with
34
+ all adjacent and all have the same non-zero value. The components
35
+ using a squared connectivity of one (all equal entries are joined with
36
36
their neighbors above,below, left, and right). Components across all
37
37
images have consecutive ids 1 through n.
38
38
Components are labeled according to the first pixel of the
@@ -42,13 +42,17 @@ def connected_components(
42
42
This op is equivalent with `scipy.ndimage.measurements.label`
43
43
on a 2D array with the default structuring element
44
44
(which is the connectivity used here).
45
+
45
46
Args:
46
- images: A 2D (H, W) or 3D (N, H, W) Tensor of boolean image(s).
47
+ images: A 2D (H, W) or 3D (N, H, W) Tensor of image (integer,
48
+ floating point and boolean types are supported).
47
49
name: The name of the op.
50
+
48
51
Returns:
49
52
Components with the same shape as `images`.
50
- False entries in `images` have value 0, and
51
- all True entries map to a component id > 0.
53
+ entries that evaluate to False (e.g. 0/0.0f, False) in `images` have
54
+ value 0, and all other entries map to a component id > 0.
55
+
52
56
Raises:
53
57
TypeError: if `images` is not 2D or 3D.
54
58
"""
0 commit comments