''' Purpose: support image black and white transformation ''' def size( original ) : ''' Purpose: return the size of the new image when performing a black and white transformation ''' nw, nh = original.size return (nw, nh) def color( opixel ) : ''' Purpose: return the new pixel when performing a black and white transformation of opixel ''' # How do I make opixel so that it is EITHER black or white? r,g,b = opixel # THIS IS IMPORTANT. We want to extract the r,g,b from the original pixel # and use the r,g,b of the original pixel to get the new color you want based # on the r,g,b values. # We want to check if the color is a lighter color or a darker color: rgb_sum = r + g + b rgb_average = rgb_sum // 3 if ( rgb_average < ( 255 // 2 ) ): # If opixel is a darker color npixel = (0,0,0) # (0,0,0) is the tuple for black else: # If opixel is a lighter color npixel = (255,255,255) # (255,255,255) is the tuple for white return npixel def where( nspot, original = None ) : ''' Purpose: return the correspondent of nspot in the original when doing a black and white 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()