''' Purpose: support image bluing transformation ''' # This module defines the size, color, and where functions to manipulate the new image # based on the old # size deals with dimensions (w,h) - Manages the new image width and height # color deals with the pixels in the image (r,g,b) - Manages the color changes for the pixels # where deals with the spots in the image (x,y) - Manages the spots in the image where pixels are placed def size( original ) : ''' Purpose: return the size of the new image when performing a bluing ''' nw, nh = original.size # Extract the width and height from the original by defining it as # w,h = original.size since original.size hands back (w,h) of the original image return (nw, nh) def color( opixel ) : ''' Purpose: return the new pixel when performing a bluing of opixel ''' # This function will change the pixels (the colors for all of the pixels in the image # in the same spots in the orignial) r, g, b = opixel # Recall that opixel passed in is a (r,g,b) pixel # A tuple is a collection that uses parentheses so (r,g,b) is a tuple # An (r,g,b) pixel defines how much red, how much green, and how much blue # there is in a color (pixel) and so the min amount for red, green, and blue # is 0 and the max amount is 255 nr = 0 # Use no red ng = 0 # Use no green nb = b # Use just the blue amount from the original pixel npixel = ( nr, ng, nb ) # Define a new pixel using (0,0,b) where b was the original blue pixel amount return npixel # The new pixel is going to be just the original blue amount pass def where( nspot, original = None ) : ''' Purpose: return the correspondent of nspot in the original when doing a bluing ''' ospot = nspot # We just want to return the original spot passed in and use that spot return ospot # The coordinates stay the same here for the images 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()