''' Purpose: support image inverse transformation ''' def size( original ) : ''' Purpose: return the size of the new image when performing a inverse transformation ''' nw, nh = original.size return (nw, nh) def color( opixel ) : ''' Purpose: return the new pixel when performing an inverse transformation of opixel, that is (255 - r, 255 - g, 255 - b), where r, g, and b are are the RGB values of opixel ''' # Return the negative color based on the opixel r,g,b we pass in r,g,b = opixel # Extract r,g,b from opixel # Modify the red, green, and blue values for the inverse pixel (npixel) nr = 255 - r ng = 255 - g nb = 255 - b npixel = ( nr, ng, nb ) return npixel # Could've also just done # r,g,b = opixel # return (255 - r, 255 - g, 255 - b) def where( nspot, original = None ) : ''' Purpose: return the correspondent of nspot in the original when performing a inverse transformation ''' ospot = nspot 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 ) original.show() new_image = manip( original, size, color, where ) new_image.show()