Skip to content

rectangularity

cellseg_gsontools.geometry.rectangularity(polygon, **kwargs)

Compute the rectangularity of a polygon.

Note

Rectangularity is the ratio of the object to the area of the minimum bounding rectangle. Rectangularity has a value of 1 for perfectly rectangular object.

Rectangularity: $$ \frac{A_{poly}}{A_{MRR}} $$

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

Parameters:

Name Type Description Default
polygon Polygon

Input shapely polygon object.

required

Returns:

Name Type Description
float float

The rectangularity value of a polygon between 0-1.

Source code in cellseg_gsontools/geometry/shape_metrics.py
def rectangularity(polygon: Polygon, **kwargs) -> float:
    """Compute the rectangularity of a polygon.

    Note:
        Rectangularity is the ratio of the object to the area of the
        minimum bounding rectangle. Rectangularity has a value of 1
        for perfectly rectangular object.

    **Rectangularity:**
    $$
    \\frac{A_{poly}}{A_{MRR}}
    $$

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

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

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

    return polygon.area / mrr.area