Skip to content

Instantly share code, notes, and snippets.

Last active Dec 29, 2020
What would you like to do?
difference of gaussians example in python
from skimage import data, feature, color, filter, 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 = filter.gaussian_filter(img,k*sigma)
s2 = filter.gaussian_filter(img,sigma)
# multiply by sigma to get scale invariance
dog = s1 - s2
print dog.min(),dog.max()
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