SHARE
TWEET

Untitled

a guest Nov 12th, 2019 95 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2.  
  3. from PIL import Image
  4. import numpy as np
  5. from scipy import ndimage
  6. import matplotlib.pyplot as plt
  7. fname = "mazeflyer.png"
  8.  
  9. img = Image.open(fname).convert('L')
  10. img = np.asarray(img)
  11.  
  12.  
  13. blur_radius = 1
  14. # smooth the image (to remove small objects)
  15. imgf = ndimage.gaussian_filter(img, blur_radius)
  16.  
  17.  
  18.  
  19. threshold_low = 5
  20. threshold_high = 250
  21. img_low = imgf > threshold_low
  22. img_high = imgf < threshold_high
  23. img_to_use = img_high & img_low
  24.  
  25.  
  26. labeled, nr_objects = ndimage.label(img_to_use)
  27. nr_objects
  28. plt.imsave('./out.png', labeled)
  29.  
  30.  
  31.  
  32. # thresholds for number of pixels
  33. low = 6
  34. high = 25
  35. for i in range(np.max):
  36.     amt = np.sum(labeled == i)
  37.     if amt > low and amt < high:
  38.         vals = np.where(labeled == 2)
  39.         out = zip(*np.where(labeled==4))
  40.  
  41.  
  42.  
  43.  
  44.  
  45.  
  46.  
  47.  
  48. nr_objects
  49.  
  50. img = Image.open(fname).convert('L')
  51. img = np.asarray(img)
  52. img = np.asarray(img)
  53.  
  54. labeled, nr_objects = ndimage.label(img)
  55. nr_objects
  56. 37
  57. plt.imsave('./out.png', labeled)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top