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
np.ndarray

Centroids heatmap. With shape (n_rows, n_cols).

Source code in pyodi/plots/boxes.py
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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 np.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
go.Figure

Heatmap figure.

Source code in pyodi/plots/boxes.py
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
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