Skip to content

shape_index

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

Compute the shape index of a polygon.

Note

Basically, the inverse of circularity.

Shape Index: $$ \frac{\sqrt{\frac{A_{poly}}{\pi}}}{\text{MBR}} $$

where \(A_{poly}\) is the area of the polygon and \(\text{MBR}\) is the radius of the minimum bounding radius.

Parameters:

Name Type Description Default
polygon Polygon

Input shapely polygon object.

required

Returns:

Name Type Description
float float

The shape index value of a polygon.

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

    Note:
        Basically, the inverse of circularity.

    **Shape Index:**
    $$
    \\frac{\\sqrt{\\frac{A_{poly}}{\\pi}}}{\\text{MBR}}
    $$

    where $A_{poly}$ is the area of the polygon and $\\text{MBR}$ is the radius of the
    minimum bounding radius.

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

    Returns:
        float:
            The shape index value of a polygon.
    """
    r = shapely.minimum_bounding_radius(polygon)
    area = polygon.area

    return np.sqrt(area / np.pi) / r