If you are working with the media
module, then you could do this:
import media
def invert():
filename = media.choose_file() # opens a select file dialog
pic = media.load_picture(filename) # converts the picture file into a "picture" as recognized by the module.
for pixel in pic:
media.set_red(pixel, 255-media.get_red(pixel)) # the inverting algorithm as suggested by @Dingle
media.set_green(pixel, 255-media.get_green(pixel))
media.set_blue(pixel, 255-media.get_blue(pixel))
print 'Done!'
The process is similar if you are using the picture
module, and looks like this:
import picture
def invert():
filename = picture.pick_a_file() # opens a select file dialog
pic = picture.make_picture(filename) # converts the picture file into a "picture" as recognized by the module.
for pixel in picture.get_pixels(pic):
picture.set_red(pixel, 255-picture.get_red(pixel)) # the inverting algorithm as suggested by @Dingle
picture.set_green(pixel, 255-picture.get_green(pixel))
picture.set_blue(pixel, 255-picture.get_blue(pixel))
print 'Done!'
Hope this helps