from PIL import Image def grayscale( original ) : ''' produce a grayscale pixels to their monochrome luminances, using NTSC formula mapping (r, g, b) to (m, m, m), where m = .299r + .587g + .114b ''' # get image dimensions ow, oh = original.size # get the dimensions of the original nw, nh = ow, oh # new image has same dimensions # create new image new = Image.new( 'RGB', (nw, nh ) ) # consider every pixel for nx in range( 0, nw ) : # consider every possible x value for ny in range( 0, nh ) : # consider every possible y value # get coordinates of interest ncoord = ( nx, ny ) ocoord = ( nx, ny ) # get color of the original pixel # determine monochrome luminance of that pixel # set new image pixel color # return the result return new if ( __name__ == '__main__' ) : # class person of interest import url # web image of interest reply = input( 'Enter web picture location: ' ) link = reply.strip() im1 = url.get_web_image( link ) im1.show() gray1 = grayscale( im1 ) gray1.show() reply = input( 'Enter id: ' ) who = reply.strip() im2 = url.get_student_image( who ) im2.show() gray2 = grayscale( im2 ) gray2.show()