Last active
March 24, 2021 22:28
-
-
Save ismael-elatifi/69f3b38cde9c2c9987686722d0d94377 to your computer and use it in GitHub Desktop.
Function to make a heatmap of gaussians taking as input the centers of the gaussians (could be useful for object detection)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import matplotlib.pyplot as plt | |
from scipy.stats import multivariate_normal | |
def points_to_gaussian_heatmap(centers, height, width, scale): | |
gaussians = [] | |
for y,x in centers: | |
s = np.eye(2)*scale | |
g = multivariate_normal(mean=(x,y), cov=s) | |
gaussians.append(g) | |
# create a grid of (x,y) coordinates at which to evaluate the kernels | |
x = np.arange(0, width) | |
y = np.arange(0, height) | |
xx, yy = np.meshgrid(x,y) | |
xxyy = np.stack([xx.ravel(), yy.ravel()]).T | |
# evaluate kernels at grid points | |
zz = sum(g.pdf(xxyy) for g in gaussians) | |
img = zz.reshape((height,width)) | |
return img |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage example :