Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from PIL import Image #Import the Image module from the PIL library
- image = Image.open('image.png') #Create a path to the image file
- rgb_image = image.convert('RGB') #Convert the image to RGB
- width, height = image.size #Assign the image's width and height to variables
- lighten_image = Image.new('RGB', (width,height)) #Create a grid for the output image
- sepia_image = Image.new('RGB', (width,height))
- #Set up loops to modify each pixel within the image
- for row in range(height):
- for col in range(width):
- r, g, b = rgb_image.getpixel((col, row))
- # a lighten filter
- lighten_image.putpixel((col, row), (min(255, r * 2),min(255, g * 2),min(255, b * 2) ))
- # a sepia filter
- sepia_image.putpixel((col, row),
- (min(255, int((0.393 * r) + (0.769 * g) + (0.189 * b))),
- min(255, int((0.349 * r) + (0.686 * g) + (0.168 * b))),
- min(255, int((0.272 * r) + (0.534 * g) + (0.131 * b)))
- ))
- lighten_image.save("lightened.png")
- sepia_image.save("sepia.png")
- lighten_image.show()
- sepia_image.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement