-
Notifications
You must be signed in to change notification settings - Fork 0
/
Umbral.py
35 lines (28 loc) · 804 Bytes
/
Umbral.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import BasicOperations as bo;
from PIL import Image
from sys import argv
def umbral():
#obtiene nombre de imagen como parametro
nombreImagen = argv[1]
#Selecciona el umbral
thresh = 0;
while thresh < 1 or thresh > 255:
thresh = input("Ingresa el umbral (1-255) : ")
#Obtiene la imagen,el tamano, y los pixeles
img = Image.open(nombreImagen)
ancho,alto = img.size
pixeles = img.load()
#Los pixeles a color los cambia a Escala de Grises
bo.toGrayScale(pixeles, ancho, alto)
#Umbral Blanco-Negro
for i in range(ancho):
for j in range(alto):
pixel = pixeles[i,j]
if pixel[0] > thresh:
newpx = 255
else:
newpx = 0
pixeles[i,j] = (newpx, newpx, newpx)
new = "umbral.jpg"
img.save(new)
print "Imagen generada con exito 'umbral.jpg'"