Create a gist now

Instantly share code, notes, and snippets.

@vane90 /binariza.py
Last active Dec 13, 2015

What would you like to do?
import sys,pygame
import Image
from math import*
from time import*
import math
def main():
pygame.init()
screen = pygame.display.set_mode((300,300))
imagen1 = binariza ()
imagen = pygame.image.load(foto1)
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit()
screen.blit(imagen,(0,0))
pygame.display.update()
def binariza():
image1 = Image.open("conv.png")
imagen1 = image1.load()
x1,y1 = image1.size
minimo = 80
for i in range(x1):
for j in range(y1):
a1 = imagen1[i,j]
rgb = (a1[0] + a1[1] + a1[2])/3
if rgb < minimo:
imagen1[i,j] = (0,0,0)
else:
imagen1[i,j] = (255,255,255)
new = 'binariza2.jpg'
image1.save(new)
return new
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment