''' Provides gamma factor corrections ''' from PIL import Image def correction( i, gf ) : ''' returns the gamma correction for gamma factor gf for value intensity i ''' gc = int( 255 * ( i / 255 ) ** ( 1 / gf ) ) return gc def pixel( p, gf ) : ''' returns a new pixel whose RGB values are gamma corrections for gamma factor gf of the RGB values of pixel p ''' r, g, b = p # a pixel is a tuple with three values: red, green, and blue # apply gamma correction to each individual color gr = correction(r, gf) gg = correction(g, gf) gb = correction(b, gf) gp = (gr, gg, gb) # reassembling the new pixel return gp def create( original, gf ) : ''' Returns a new image whose dimensions match that of original, where a pixel in the new image is a gamma correction for gamma factor gf of the corresponding pixel in original ''' ow, oh = original.size nw, nh = ow, oh new_image = Image.new( 'RGB', ( nw, nh ) ) for nx in range( 0, nw ) : for ny in range( 0, nh ) : nspot = (nx, ny ) ospot = nspot opixel = original.getpixel( ospot ) npixel = pixel( opixel, gf ) new_image.putpixel( nspot, npixel ) return new_image if ( __name__ == '__main__' ) : import url import gamma link = 'http://www.cs.virginia.edu/~cs1112/images/mandrill/full.png' reply = input( "Enter email id: " ) id = reply.strip().lower() original = url.get_selfie( id ) im = gamma.create( original, 0.25 ) im.show() im = gamma.create( original, 2.00 ) im.show()