''' Purpose: support image grayscale transformation ''' def size( original ) : ''' Purpose: return the size of the new image when performing a grayscale transformation ''' nw, nh = original.size return (nw, nh) def color( opixel ) : ''' Purpose: return the new pixel when performing a grayscale transformation of opixel ''' r,g,b = opixel m = ( r + g + b ) // 3 # m is the average of r,g,b npixel = ( m, m, m ) # The new pixel is just where the r,g,b is set to m return npixel def where( nspot, original = None ) : ''' Purpose: return the correspondent of nspot in the original when performing a grayscale 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()