-
-
Save afrendeiro/231dac9f3b046b83be6c70f451c231b3 to your computer and use it in GitHub Desktop.
difference of gaussians example in python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.subplot(2,3,1) | |
plt.imshow(original_image) | |
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.subplot(2,3,idx+2) | |
print(dog.min(),dog.max()) | |
plt.imshow(dog,cmap='RdBu') | |
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) | |
ax.add_patch(c) | |
plt.imshow(img_blobs) | |
plt.title('Detected DoG Maxima') | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment