Skip to content

Instantly share code, notes, and snippets.

@ThomasParistech
Created July 17, 2024 13:58
Show Gist options
  • Save ThomasParistech/f4216d05e6a732f43306938875f0b860 to your computer and use it in GitHub Desktop.
Save ThomasParistech/f4216d05e6a732f43306938875f0b860 to your computer and use it in GitHub Desktop.
import cv2
def ceil_odd(x: float) -> int:
"""Round float to nearest odd integer."""
return 1 + 2*math.ceil(0.5*(x-1.0))
# Perform KDE and retrieve the bandwidth
kde = gaussian_kde(disk_xy.T)
sigma = np.sqrt(kde.covariance[0, 0])
# Scale the bandwidth and round it to nearest odd integer
sigma_pix = sigma * n_rows / 2.
ksize = ceil_odd(10*sigma_pix)
# Perform Gaussian Convolution on binary disk mask
gaussian_blurred = cv2.GaussianBlur(disk_mask.astype(np.float32),
ksize=(ksize, ksize),
sigmaX=sigma_pix, sigmaY=sigma_pix,
borderType=cv2.BORDER_CONSTANT)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment