Skip to content

equivalent_rectangular_index

cellseg_gsontools.geometry.equivalent_rectangular_index(polygon)

Compute the equivalent rectangular index.

Note

Equivalent rectangluar index is the deviation of a polygon from an equivalent rectangle.

ERI: $$ \frac{\sqrt{A_{poly}}}{A_{MRR}} \times \frac{P_{MRR}}{P_{poly}} $$

where \(A_{poly}\) is the area of the polygon, \(A_{MRR}\) is the area of the minimum rotated rectangle, \(P_{MRR}\) is the perimeter of the minimum rotated rectangle and \(P_{poly}\) is the perimeter of the polygon.

Parameters:

Name Type Description Default
polygon Polygon

Input shapely polygon object.

required

Returns:

Name Type Description
float float

The ERI value of a polygon between 0-1.

Source code in cellseg_gsontools/geometry/shape_metrics.py
def equivalent_rectangular_index(polygon: Polygon) -> float:
    """Compute the equivalent rectangular index.

    Note:
        Equivalent rectangluar index is the deviation of a polygon from
        an equivalent rectangle.

    **ERI:**
    $$
    \\frac{\\sqrt{A_{poly}}}{A_{MRR}}
    \\times
    \\frac{P_{MRR}}{P_{poly}}
    $$

    where $A_{poly}$ is the area of the polygon, $A_{MRR}$ is the area of the
    minimum rotated rectangle, $P_{MRR}$ is the perimeter of the minimum rotated
    rectangle and $P_{poly}$ is the perimeter of the polygon.

    Parameters:
        polygon (Polygon):
            Input shapely polygon object.

    Returns:
        float:
            The ERI value of a polygon between 0-1.
    """
    mrr = polygon.minimum_rotated_rectangle

    return np.sqrt(polygon.area / mrr.area) / (mrr.length / polygon.length)