Skip to content

elongation

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

Compute the elongation of a polygon.

Note

Elongation is the ratio between the length and width of the object bounding box. If the ratio is equal to 1, the object is roughly square or circularly shaped. As the ratio decreases from 1, the object becomes more elongated. - Wirth

Elongation: $$ \frac{\text{bbox width}}{\text{bbox height}} $$

Parameters:

Name Type Description Default
polygon Polygon

Input shapely polygon object.

required

Returns:

Name Type Description
float float

The elongation value of a polygon between 0-1.

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

    Note:
        Elongation is the ratio between the length and width of the
        object bounding box. If the ratio is equal to 1, the object
        is roughly square or circularly shaped. As the ratio decreases
        from 1, the object becomes more elongated.
        - [Wirth](http://www.cyto.purdue.edu/cdroms/micro2/content/education/wirth10.pdf)

    **Elongation:**
    $$
    \\frac{\\text{bbox width}}{\\text{bbox height}}
    $$

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

    Returns:
        float:
            The elongation value of a polygon between 0-1.
    """
    minx, miny, maxx, maxy = polygon.bounds

    width = maxx - minx
    height = maxy - miny

    if width <= height:
        elongation = width / height
    else:
        elongation = height / width

    return elongation