Advertisement
Guest User

Untitled

a guest
Apr 16th, 2014
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. from PIL import Image
  2. import numpy as np
  3. im = Image.open("/Users/Hugo/green_leaves.jpg")
  4. im.load()
  5. height, widht = im.size
  6. p = np.array([0,0,0])
  7. for row in range(height):
  8. for col in range(widht):
  9. a = im.getpixel((row,col))
  10. p = np.append(a.asarray())
  11.  
  12. Traceback (most recent call last):
  13. File "/Users/hugo/PycharmProjects/Meteo API/image.py", line 17, in <module>
  14. p = np.append(a.asarray())
  15. AttributeError: 'tuple' object has no attribute 'asarray'
  16.  
  17. from PIL import Image
  18. import numpy as np
  19. im = Image.open("/Users/Hugo/green_leaves.jpg")
  20. p = np.array(im)
  21.  
  22. p = p.reshape(-1, p.shape[2])
  23.  
  24. p=[]
  25. for row in range(height):
  26. for col in range(widht):
  27. a = im.getpixel((row,col))
  28. p.append(a)
  29. p=np.asarray(p)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement