Skip to content

fractal_dimension

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

Compute the fractal dimension of a polygon.

Note

The fractal dimension is the rate at which the perimeter of an object increases as the measurement scale is reduced. The fractal dimension produces a single numeric value that summarizes the irregularity of "roughness" of the feature boundary. - Wirth

Fractal dimension: $$ 2 \times \frac{\log(\frac{P_{poly}}{4})}{\log(A_{poly})} $$

where \(P_{poly}\) is the perimeter of the polygon and \(A_{poly}\) is the area of the polygon.

Parameters:

Name Type Description Default
polygon Polygon

Input shapely polygon object.

required

Returns:

Name Type Description
float float

The fractal dimension value of a polygon.

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

    Note:
        The fractal dimension is the rate at which the perimeter of an
        object increases as the measurement scale is reduced. The fractal
        dimension produces a single numeric value that summarizes the
        irregularity of "roughness" of the feature boundary.
        - [Wirth](http://www.cyto.purdue.edu/cdroms/micro2/content/education/wirth10.pdf)


    **Fractal dimension:**
    $$
    2 \\times \\frac{\\log(\\frac{P_{poly}}{4})}{\\log(A_{poly})}
    $$

    where $P_{poly}$ is the perimeter of the polygon and $A_{poly}$ is the area of the
    polygon.

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

    Returns:
        float:
            The fractal dimension value of a polygon.
    """
    perimeter = polygon.length
    area = polygon.area

    return (2 * np.log(perimeter / 4)) / np.log(area)