W3cubDocs

/TensorFlow Python

tf.contrib.image.connected_components

tf.contrib.image.connected_components(images)

Defined in tensorflow/contrib/image/python/ops/image_ops.py.

Labels the connected components in a batch of images.

A component is a set of pixels in a single input image, which are all adjacent and all have the same non-zero value. The components using a squared connectivity of one (all True entries are joined with their neighbors above, below, left, and right). Components across all images have consecutive ids 1 through n. Components are labeled according to the first pixel of the component appearing in row-major order (lexicographic order by image_index_in_batch, row, col). Zero entries all have an output id of 0.

This op is equivalent with scipy.ndimage.measurements.label on a 2D array with the default structuring element (which is the connectivity used here).

Args:

  • images: A 2D (H, W) or 3D (N, H, W) Tensor of boolean image(s).

Returns:

Components with the same shape as images. False entries in images have value 0, and all True entries map to a component id > 0.

Raises:

  • TypeError: if images is not 2D or 3D.

© 2018 The TensorFlow Authors. All rights reserved.
Licensed under the Creative Commons Attribution License 3.0.
Code samples licensed under the Apache 2.0 License.
https://www.tensorflow.org/api_docs/python/tf/contrib/image/connected_components