''' Purpose: support image bluing transformation ''' def size( original ) : ''' Purpose: return the size of the new image when performing a bluing ''' nw, nh = original.size # Extract width and height and just return it for the original size return (nw, nh) def color( p ) : ''' Returns a new pixel whose RGB values are the inverse of pixel p, that is (255 - r, 255 - g, 255 - b), where r, g, and b are are the RGB values of pixel p ''' r,g,b = p # Extract the original r, g, b values from the pixel p nr = 255 - r ng = 255 - g nb = 255 - b npixel = ( nr, ng, nb ) # New pixel we're returning with the new r,g,b amounts return npixel def where( nspot, original = None ) : ''' Purpose: return the correspondent of nspot in the original when doing a bluing ''' ospot = nspot # Use the original spots return ospot if ( __name__ == '__main__' ) : import url from manip import manip # get web image of interest link = "http://www.cs.virginia.edu/~cs1112/images/mandrill/full.png" original = url.get_image( link ) new_image = manip( original, size, color, where ) new_image.show()