Skip to content

Instantly share code, notes, and snippets.

Forked from leonidk/
Created December 29, 2020 16:30
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
difference of gaussians example in python
from skimage import data, feature, color, filters, img_as_float
from matplotlib import pyplot as plt
original_image = img_as_float(data.chelsea())
img = color.rgb2gray(original_image)
k = 1.6
plt.title('Original Image')
for idx,sigma in enumerate([4.0,8.0,16.0,32.0]):
s1 = filters.gaussian(img,k*sigma)
s2 = filters.gaussian(img,sigma)
# multiply by sigma to get scale invariance
dog = s1 - s2
plt.title('DoG with sigma=' + str(sigma) + ', k=' + str(k))
ax = plt.subplot(2,3,6)
blobs_dog = [(x[0],x[1],x[2]) for x in feature.blob_dog(img, min_sigma=4, max_sigma=32,threshold=0.5,overlap=1.0)]
# skimage has a bug in my version where only maxima were returned by the above
blobs_dog += [(x[0],x[1],x[2]) for x in feature.blob_dog(-img, min_sigma=4, max_sigma=32,threshold=0.5,overlap=1.0)]
#remove duplicates
blobs_dog = set(blobs_dog)
img_blobs = color.gray2rgb(img)
for blob in blobs_dog:
y, x, r = blob
c = plt.Circle((x, y), r, color='red', linewidth=2, fill=False)
plt.title('Detected DoG Maxima')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment