Skip to content

Instantly share code, notes, and snippets.

@monogenea
Last active May 3, 2026 11:42
Show Gist options
  • Select an option

  • Save monogenea/f25c4ff54e0bad48ce477404b525c01b to your computer and use it in GitHub Desktop.

Select an option

Save monogenea/f25c4ff54e0bad48ce477404b525c01b to your computer and use it in GitHub Desktop.
# LoG: positive sigma = apply Gaussian of that std, then Laplacian
log_response = gaussian_laplace(image.astype(float), sigma=2.0)
# Zero-crossings: sign changes between neighbouring pixels
def zero_crossings(log_img):
"""Return a binary mask of zero-crossing locations."""
zc = np.zeros_like(log_img, dtype=bool)
# Check horizontal and vertical sign changes
for shift in [(0, 1), (1, 0)]:
shifted = np.roll(log_img, shift=shift, axis=(0, 1))
zc |= (np.sign(log_img) != np.sign(shifted))
return zc
zc_mask = zero_crossings(log_response)
fig, axes = plt.subplots(1, 2, figsize=(10, 4))
axes[0].imshow(log_response, cmap='RdBu_r')
axes[0].set_title('LoG response (σ=2.0)')
axes[0].axis('off')
axes[1].imshow(zc_mask, cmap='gray')
axes[1].set_title('Zero-crossings')
axes[1].axis('off')
plt.tight_layout()
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment