Advertisement
danimtzcvm

Entrada - Imagen a binario en archivo

Oct 9th, 2012
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.73 KB | None | 0 0
  1. #!/usr/bin/env python
  2.  
  3. #Importamos las librerias necesarias
  4. import Image, sys
  5.  
  6. #Creamos un nuevo archivo para guardas los datos binarios
  7. f = open("img1.txt", "w")
  8.  
  9. #Variables
  10. x = 1
  11. y = 1
  12.  
  13. #Abrimos la huella que ocupamos
  14. im = Image.open("img1.png")
  15.  
  16. #Hacemos un recorrido en largo y ancho de la imagen por pixeles
  17. for y in range(0,209): #Largo
  18.     for x in range(0,180): #Ancho
  19.         pix = im.load()            
  20.         pix[x, y]
  21.                 if pix[x,y] == (255,255,255):  #Si se encuentra un punto blanco se guarda 1
  22.                     c= 1
  23.         else:
  24.             c= 0                   #Si no es blanco entonces se guarda 0
  25.         f.write(str(c))            #Escribimos en el archivo
  26.     f.write('\n')
  27. f.close()                          #Cerramos el archivo
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement