Skip to content

Instantly share code, notes, and snippets.

@chexov
Last active July 29, 2025 11:45
Show Gist options
  • Save chexov/1157499c429a7bcaca082787091f034a to your computer and use it in GitHub Desktop.
Save chexov/1157499c429a7bcaca082787091f034a to your computer and use it in GitHub Desktop.

Revisions

  1. chexov revised this gist Sep 23, 2019. 1 changed file with 0 additions and 1 deletion.
    1 change: 0 additions & 1 deletion gaussian_heatmap.py
    Original file line number Diff line number Diff line change
    @@ -3,7 +3,6 @@


    def gaussian_heatmap(sigma: int, spread: int):
    global heatmap
    extent = int(spread * sigma)
    center = spread * sigma / 2
    heatmap = numpy.zeros([extent, extent], dtype=numpy.float32)
  2. chexov created this gist Sep 23, 2019.
    22 changes: 22 additions & 0 deletions gaussian_heatmap.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,22 @@
    import cv2
    import numpy


    def gaussian_heatmap(sigma: int, spread: int):
    global heatmap
    extent = int(spread * sigma)
    center = spread * sigma / 2
    heatmap = numpy.zeros([extent, extent], dtype=numpy.float32)
    for i_ in range(extent):
    for j_ in range(extent):
    heatmap[i_, j_] = 1 / 2 / numpy.pi / (sigma ** 2) * numpy.exp(
    -1 / 2 * ((i_ - center - 0.5) ** 2 + (j_ - center - 0.5) ** 2) / (sigma ** 2))
    heatmap = (heatmap / numpy.max(heatmap) * 255).astype(numpy.uint8)
    return heatmap


    hm = gaussian_heatmap(sigma=10, spread=3)

    hm = cv2.applyColorMap(hm, cv2.COLORMAP_JET)
    cv2.imshow("hm", hm)
    cv2.waitKey(0)