It should be possible to do this through PIL. Here is a rough outline of the steps:
1) Load the image and convert to numpy array
im = Image.open('myimage.png').convert('RGBA')
matrix = numpy.array(im)
2) Modify the matrix in place. The matrix is a list of lists of the pixels within each row. Pixels are represented as [r, g, b, a]. Write your own function to convert each [r, g, b, a] pixel to the [r, g, b] value you desire.
3) Convert the matrix back to an image using
new_im = Image.fromarray(matrix)