10. ImageChops invert
10.1. Invert
Use the
ImageChops.invert(image)
method to invert an image.out = MAX - image
- ImageChops.invert(image)
- returns an inverted imageimage is the image to invert.
The code below inverts an image.
The original png is in RGBA mode so when inverted unexpected results are seen.
After converting to RGB mode, the colours are inverted as expected.
from PIL import Image, ImageChops
with Image.open("test_images/circles.png") as im:
im_inv = ImageChops.invert(im)
im_inv.save("chops/invert.png")