''' Purpose: support image mirroring transformation ''' def mirror( nspot, nw, nh ) : ''' Returns the correspondent of nspot in its nw x ny image in the unmirrored original ''' # nw and nh are the dimensions of the new image # since we're not changing the dimensions, they are also the dimensions for the original image nx, ny = nspot # separate the x and y points of nspot (the spot in the new image we're looking at) # need to find ox, oy to get the ospot in the original image # ox is different because we've mirrored over the y-axis # so what is on the left side of the new image needs to be colored using # the pixels on the right side of the original image # how far are you from the width of the image/from the right side of the image # GOTCHA: the last index of nx is ALWAYS one less than the width of the image # so each spot from the right as we progress to the left of the original image is one less than we want ox = (nw - 1) - nx oy = ny # the same y distance, did not change ospot = ( ox, oy ) # the coordinate of the spot in the original image that we want to look at return ospot # we are going from the new image to the old image is because we are trying to create the new image. # for each of the pixel in the new image, from left to right, top to bottom, we need to find the color at # the corresponding position from the old image to paint the new spot. # we could go from the original to the new image, but here, we will paint the new image and look back to the original 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, where=mirror ) new_image.show()