Advertisement
Guest User

binary_image

a guest
Mar 29th, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.51 KB | None | 0 0
  1. import os
  2. from PIL import Image
  3. import numpy as np
  4.  
  5. os.chdir("./data")
  6. files = os.listdir()
  7. final = []
  8. for i in range (10):
  9.  
  10. im = Image.open(files[i])
  11. threshold = 252
  12. im=im.resize((28,28), Image.ANTIALIAS)
  13. im = im.point(lambda p: p > threshold and 255)
  14. na = np.array(im)
  15. img=(na > na.mean())*255
  16. np.place(na,na<255,1)
  17. np.place(na,na==255,0)
  18. fa=na.reshape([1,784])
  19. fa = list(fa)
  20. final = final + fa
  21.  
  22.  
  23. print(final[3])
  24. im.show(final[6].reshape(28,28))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement