''' Purpose: support image bluing transformation ''' # We want to define functions to manipulate dimensions, color, and locations of spots. # We know that to blue an image, it's going to be the same dimension and all the spots # (x,y) coordinates will be at the same locations! BUTTT the color will be different! # So the only thing that will change is that we will change the colors to blues. def size( original ) : ''' Purpose: return the size of the new image when performing a bluing ''' nw, nh = original.size return (nw, nh) def color( opixel ) : ''' Purpose: return the new pixel when performing a bluing of opixel ''' # We want to take the original pixel color (r,g,b) and only use the b (the blue value) # Recall a pixel is a tuple (r,g,b) so opixel is a color in our image (r,g,b) # Remember doing r,g,b = opixel is kinda like how we could do # a,b = [1,2] -> the variable a gets the 1 and the variable b gets the 2 # so opixel is (r,g,b) tuple that are ACTUAL VALUES like (24,52,240) and we can simply # assign r to the 24 g to the 52 and b to the 240 # We're just taking the values from the original tuple and assigning them to these variables! # opixel is a single color. r,g,b = opixel # Extract r,g,b from the opixel passed in! npixel = ( 0, 0, b ) # Use the b value from the original pixel return npixel def where( nspot, original = None ) : ''' Purpose: return the correspondent of nspot in the original when doing a bluing ''' 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()