Python Pillow: Invert Image Color Using ImageOps.invert()

In this tutorial, we will use an example to introduce how to useĀ ImageOps.invert() to invert image color in python pillow.

Python Pillow - Invert Image Color Using ImageOps.invert() for Beginners

1.Open an image

from PIL import Image, ImageOps

im = Image.open('data/src/horse.png').convert('RGB')

2.Invert image color usingĀ ImageOps.invert()

im_invert = ImageOps.invert(im)

3.Save inverted image

im_invert.save('data/dst/horse_invert.png')

Run this code, you will see this inverted image:

Python Pillow - Invert Image Color Using ImageOps.invert()