labels2contours

tomni.transformers.labels2contours(labels: numpy.ndarray, simplify_error: float = 0, return_inner_contours: bool = False) list[source]

Convert a labeled image into a list of OpenCV contours.

Parameters
  • labels (np.ndarray) – An array where every pixel is labeled to indicate which object it belongs to. The labels should be non-negative integers.

  • return_inner_contours (bool, optional) – If True, return the internal contours (contours around holes within objects). If False (default), return only the external contours (outlines of objects).

Returns

A list of OpenCV-style contours represented as NumPy arrays. Each contour is a 2D array

with shape (N, 1, 2), where N is the number of points in the contour, and each point has (x, y) coordinates. The list contains contours for each labeled object in the input image.

Return type

List[np.ndarray]

Warning

  • The parameter ‘simplify_error’ has been deprecated and is no longer used. Please update your code to remove references to ‘simplify_error’.