Skip to content

Instantly share code, notes, and snippets.

View ismael-elatifi's full-sized avatar

ismael-elatifi

  • Paris
View GitHub Profile
@ismael-elatifi
ismael-elatifi / minimum_spanning_tree_binary_image.py
Last active March 24, 2021 23:38
Compute minimum spanning tree in binary image (nodes are white pixels) using Prim's algorithm
import cv2
import numpy as np
from heapq import heappush, heappop
def find_pixels_in_window(img, x, y, window_size):
d = window_size//2
y_start = max(y-d,0)
x_start = max(x-d,0)
window = img[y_start:y+d+1, x_start:x+d+1]
ay, ax = np.where(window > 0)
@ismael-elatifi
ismael-elatifi / points_to_heatmap.py
Last active March 24, 2021 22:28
Function to make a heatmap of gaussians taking as input the centers of the gaussians (could be useful for object detection)
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)