# 2D contours representation and simplification¶

 fit_contour_2d(*args, **kwargs) Overloaded function. Contour2d A contour2d is a set of polyline contours. PolylineContour2d A polyline contour is an ordered list of contour segment that form a continuous piece of frontier between 2 regions. ContourSegment2d A contour segment is an ordered list of contour elements that are considered to form a straight line segment.A contour element is a pair (edge_index, coordinates) where coordinates is a 2d point.
fit_contour_2d(*args, **kwargs)

1. fit_contour_2d(graph: hg::undirected_graph_internal::undirected_graph<hg::undirected_graph_internal::vecS>, shape: List[int], edgeWeights: numpy.ndarray[numpy.int8]) -> higra.higram.Contour2d

Construct a contour_2d object from a graph cut of a 2d image with a 4 adjacency (non zero edges are part of the cut).

1. fit_contour_2d(graph: hg::undirected_graph_internal::undirected_graph<hg::undirected_graph_internal::vecS>, shape: List[int], edgeWeights: numpy.ndarray[numpy.uint8]) -> higra.higram.Contour2d

2. fit_contour_2d(graph: hg::undirected_graph_internal::undirected_graph<hg::undirected_graph_internal::vecS>, shape: List[int], edgeWeights: numpy.ndarray[numpy.int16]) -> higra.higram.Contour2d

3. fit_contour_2d(graph: hg::undirected_graph_internal::undirected_graph<hg::undirected_graph_internal::vecS>, shape: List[int], edgeWeights: numpy.ndarray[numpy.uint16]) -> higra.higram.Contour2d

4. fit_contour_2d(graph: hg::undirected_graph_internal::undirected_graph<hg::undirected_graph_internal::vecS>, shape: List[int], edgeWeights: numpy.ndarray[numpy.int32]) -> higra.higram.Contour2d

5. fit_contour_2d(graph: hg::undirected_graph_internal::undirected_graph<hg::undirected_graph_internal::vecS>, shape: List[int], edgeWeights: numpy.ndarray[numpy.uint32]) -> higra.higram.Contour2d

6. fit_contour_2d(graph: hg::undirected_graph_internal::undirected_graph<hg::undirected_graph_internal::vecS>, shape: List[int], edgeWeights: numpy.ndarray[numpy.int64]) -> higra.higram.Contour2d

7. fit_contour_2d(graph: hg::undirected_graph_internal::undirected_graph<hg::undirected_graph_internal::vecS>, shape: List[int], edgeWeights: numpy.ndarray[numpy.uint64]) -> higra.higram.Contour2d

8. fit_contour_2d(graph: hg::undirected_graph_internal::undirected_graph<hg::undirected_graph_internal::vecS>, shape: List[int], edgeWeights: numpy.ndarray[numpy.float32]) -> higra.higram.Contour2d

9. fit_contour_2d(graph: hg::undirected_graph_internal::undirected_graph<hg::undirected_graph_internal::vecS>, shape: List[int], edgeWeights: numpy.ndarray[numpy.float64]) -> higra.higram.Contour2d

class Contour2d

A contour2d is a set of polyline contours. Each polyline contour represent a continuous piece of contour between two regions.

__getitem__(self: higra.higram.Contour2d, arg0: int) → higra.higram.PolylineContour2d
__init__()

Initialize self. See help(type(self)) for accurate signature.

__iter__(self: higra.higram.Contour2d) → Iterator

Iterator on the polyline contours.

__len__(self: higra.higram.Contour2d) → int

Number of polyline contours.

subdivide(self: higra.higram.Contour2d, epsilon: float = 0.1, relative_epsilon: bool = True, min_size: int = 2) → None

Subdivide each segment of the contour such that: For each segment, the distance between the line joining the extremities of the segment and each of its elements is lower than the given threshold (Ramer–Douglas–Peucker algorithm) or smaller than the minimal specified size The threshold is equal to - epsilon if relative_epsilon is false - epsilon times the distance between the segment extremities if relative_epsilon is true

Implementation note: simply call subdivide on each polyline of the contour.

class PolylineContour2d

A polyline contour is an ordered list of contour segment that form a continuous piece of frontier between 2 regions. Note that consecutive segments share their extremities: given two consecutive contour segments s1 and s2, the last element of s1 is equal to the first element of s2.

__getitem__(self: higra.higram.PolylineContour2d, arg0: int) → higra.higram.ContourSegment2d
__init__()

Initialize self. See help(type(self)) for accurate signature.

__iter__(self: higra.higram.PolylineContour2d) → Iterator

Iterator on the contour segments of the polyline contour.

__len__(self: higra.higram.PolylineContour2d) → int

Number of segments in the polyline contour.

subdivide(self: higra.higram.PolylineContour2d, epsilon: float = 0.1, relative_epsilon: bool = True, min_size: int = 2) → None

Subdivide the line such that the distance between the line joining the extremities of the contour segment and each of its elements is lower than the threshold ( Ramer–Douglas–Peucker algorithm) or smaller than the minimal specified size

The threshold is equal to - epsilon if relative_epsilon is false - epsilon times the distance between the segment extremities if relative_epsilon is true

class ContourSegment2d

A contour segment is an ordered list of contour elements that are considered to form a straight line segment.A contour element is a pair (edge_index, coordinates) where coordinates is a 2d point.

__getitem__(self: higra.higram.ContourSegment2d, arg0: int) → Tuple[int, Tuple[float, float]]
__init__()

Initialize self. See help(type(self)) for accurate signature.

__iter__(self: higra.higram.ContourSegment2d) → Iterator

Iterator on the contour elements of the contour segment.

__len__(self: higra.higram.ContourSegment2d) → int

Number of elements in the contour segment.

angle(self: higra.higram.ContourSegment2d) → float

Angle of the vector (last()-first()) in [-pi; pi].

distance_to_point(self: higra.higram.ContourSegment2d, point: numpy.ndarray[numpy.float64]) → float

Distance between the given point and the line defined by the fist and last element of the contour segment.

norm(self: higra.higram.ContourSegment2d) → float

Distance between first and last elements of the contour segment.