En
el laboratorio 1 se pidió procesar una imagen y convertirla a escala de grises.
Para
eso primero recorro cada pixel de la imagen y promedio la suma de los colores
de cada pixel y asigno ese valor.
Por
ejemplo si el color de un pixel es (100,120,80) asignaría a ese pixel el valor
de (200,200,200).
Aquí
les muestro el código:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
import pygame | |
from pygame.locals import * | |
import Image | |
pygame.init() | |
ventana=pygame.display.set_mode((1024,768)) | |
imagen=pygame.image.load("imagen.jpg") | |
ventana.blit(imagen,(0,0)) | |
pygame.display.update() | |
im = Image.open("imagen.jpg") | |
pix = im.load() | |
for x in range(0,1024): #Ancho | |
for y in range(0,768): #Largo | |
(r,g,b) = pix[x,y] | |
promedio=(r+g+b)/3 | |
pix[x,y] =(promedio,promedio,promedio) | |
im.save('escala.jpg') | |
esc=pygame.image.load("escala.jpg") | |
ventana.blit(esc,(0,0)) | |
pygame.display.update() | |
while True: | |
for event in pygame.event.get(): | |
if event.type == QUIT: | |
exit() |
1 comentario:
Bien poquito que hiciste :( 5 pts.
Publicar un comentario