views:

46

answers:

0

Possible Duplicate:
Python (creating a negative of this black and white image)

Hi,

I am trying to create a negative of this black and white image. The opposite of white (255) is black (0) and vice versa. The opposite of a pixel with a value of 100 is 155. I cannot use convert, invert, point, eval, lambda.

Here is my code but it doesnt work yet. Could you please let me know which part I am wrong? Thanks for any help.

def bw_negative(filename):
"""
This function creates a black and white negative of a bitmap image
using the following parameters:
   filename is the name of the bitmap image
"""
#Create the handle and then create a list of pixels.
image = Image.open(filename)
pixels = list(image.getdata())

for pixel in pixels:
    red=pixel[0]
    green=pixel[1]
    blue=pixel[2]        
    negColor = makeColor(255-red, green, blue)
    setColor(pixel,negColor)


image.putdata(pixels)
image.save ('new.bmp')