Advertisement
Guest User

Untitled

a guest
Oct 25th, 2016
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. from skimage import data, feature, color, filter, img_as_float
  2. from matplotlib import pyplot as plt
  3.  
  4.  
  5. original_image = img_as_float(data.chelsea())
  6. img = color.rgb2gray(original_image)
  7.  
  8. k = 1.6
  9.  
  10. plt.subplot(2,3,1)
  11. plt.imshow(original_image)
  12. plt.title('Original Image')
  13.  
  14. for idx,sigma in enumerate([4.0,8.0,16.0,32.0]):
  15. s1 = filter.gaussian_filter(img,k*sigma)
  16. s2 = filter.gaussian_filter(img,sigma)
  17.  
  18. # multiply by sigma to get scale invariance
  19. dog = s1 - s2
  20. plt.subplot(2,3,idx+2)
  21. print dog.min(),dog.max()
  22. plt.imshow(dog,cmap='RdBu')
  23. plt.title('DoG with sigma=' + str(sigma) + ', k=' + str(k))
  24.  
  25. ax = plt.subplot(2,3,6)
  26. 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)]
  27. # skimage has a bug in my version where only maxima were returned by the above
  28. 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)]
  29.  
  30. #remove duplicates
  31. blobs_dog = set(blobs_dog)
  32.  
  33. img_blobs = color.gray2rgb(img)
  34. for blob in blobs_dog:
  35. y, x, r = blob
  36. c = plt.Circle((x, y), r, color='red', linewidth=2, fill=False)
  37. ax.add_patch(c)
  38. plt.imshow(img_blobs)
  39. plt.title('Detected DoG Maxima')
  40.  
  41. plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement