Friday, September 25, 2009

Python - replace or remove colors from an image

from PIL import Image
# this script assumes that 'test.jpg' 
# is in the current working directory 
n ='test.jpg')
m = n.load()
# get x,y size 
s = n.size
# iterate through x and y (every pixel) 
for x in xrange(s[0]):
    for y in xrange(s[1]):
        r,g,b = m[x,y]
        # remove red from the pic 
        m[x,y] = 0,g,b
# save the doctored image'sans_red.jpg', "JPEG")
# removing all the red from a photo 
# makes for a creepy greenish blue (duh..with no red) 
# try it out! 

No comments:

Post a Comment