Skip to content

boxes

get_centroids_heatmap(df, n_rows=9, n_cols=9)

Returns centroids heatmap.

Parameters:

Name Type Description Default
df DataFrame

DataFrame with annotations.

required
n_rows int

Number of rows.

9
n_cols int

Number of columns.

9

Returns:

Type Description
ndarray

Centroids heatmap. With shape (n_rows, n_cols).

Source code in pyodi/plots/boxes.py
def get_centroids_heatmap(
    df: DataFrame, n_rows: int = 9, n_cols: int = 9
) -> np.ndarray:
    """Returns centroids heatmap.

    Args:
        df: DataFrame with annotations.
        n_rows: Number of rows.
        n_cols: Number of columns.

    Returns:
        Centroids heatmap. With shape (`n_rows`, `n_cols`).

    """
    rows = df["row_centroid"] / df["img_height"]
    cols = df["col_centroid"] / df["img_width"]
    heatmap = np.zeros((n_rows, n_cols))
    for row, col in zip(rows, cols):
        heatmap[int(row * n_rows), int(col * n_cols)] += 1

    return heatmap

plot_heatmap(heatmap, title='', show=True, output=None, output_size=(1600, 900))

Plots heatmap figure.

Parameters:

Name Type Description Default
heatmap ndarray

Heatmap (2D array) data to plot.

required
title str

Title of the figure. Defaults to "".

''
show bool

Whether to show results or not. Defaults to True.

True
output Optional[str]

Results will be saved under output dir. Defaults to None.

None
output_size Tuple[int, int]

Size of the saved images when output is defined. Defaults to (1600, 900).

(1600, 900)

Returns:

Type Description
Figure

Heatmap figure.

Source code in pyodi/plots/boxes.py
def plot_heatmap(
    heatmap: np.ndarray,
    title: str = "",
    show: bool = True,
    output: Optional[str] = None,
    output_size: Tuple[int, int] = (1600, 900),
) -> go.Figure:
    """Plots heatmap figure.

    Args:
        heatmap: Heatmap (2D array) data to plot.
        title: Title of the figure. Defaults to "".
        show: Whether to show results or not. Defaults to True.
        output: Results will be saved under `output` dir. Defaults to None.
        output_size: Size of the saved images when output is defined. Defaults to
            (1600, 900).

    Returns:
        Heatmap figure.

    """
    fig = go.Figure(data=go.Heatmap(z=heatmap))

    fig.update_layout(title_text=title, title_font_size=20)

    fig.update_xaxes(showticklabels=False)
    fig.update_yaxes(showticklabels=False)

    if show:
        fig.show()

    if output:
        save_figure(fig, title, output, output_size)

    return fig