The concept of inverting an image can mean a few things. One possible meaning is that you are flipping an image. However, in this chapter, you are using ImageChops
, which means that you are doing a channel operation. In that context, it means that you are inverting the colors or creating a negative of the image.
Here is the definition of the invert()
function from the Pillow package’s ImageChops module:
This takes in an image object and does some magic to invert the image.
For this example, you will re-use this image of a lovely butterfly from a previous tutorial:
Create a new file and name it invert_image.py
. Then add the following code to your file:
Your code is a bit simpler than the previous examples in this chapter. That is because you are only working with one image rather than two.
When you run your code, you will end up with this result:
The ImageChop.invert()
function does not give you any control over the inversion process. But it does give you an easy way to create a negative version of your images.
Your last post got me looking at the ImageChops module (which I'd ignored up to now). Very handy tool!