Introduction to ImageOps Module in Pillow

FeaImg ImageOps

Hello there, programmers! In this tutorial, we’ll look at Python’s ImageOps module.

This module includes a number of pre-built image processing methods. Furthermore, the majority of operators only deal with L and RGB pictures. The ImageOps module’s many functions are listed below.


Original Image Chosen

ImageOps Original Image
ImageOps Original Image

AutoConstrast Function Using Pillow

The auto contrast feature is used to equalize the contrast of a picture. It requires three parameters: image, cutoff, and ignore. To process the image, use the image argument.

To normalize the picture contrast, the cutoff value is employed. The ignore argument is used to suppress the background pixels. This function yields a picture as a result.

from PIL import ImageOps, Image
img = Image.open('pic1.jpg')
img2 = ImageOps.autocontrast(img, cutoff=40)
img2.show()
ImageOps Autocontrast
ImageOps Autocontrast

Colorize Function Using Python Pillow

Colorize grayscale photos with this function. It necessitates the use of a total of seven parameters. The first argument is the picture to be colored. The second option is black, which accepts only black pixels as input.

Similarly, the third argument is white, which accepts white pixels as input. The fourth option, mid, is utilized for midtone input pixels. The final three parameters are the black point, the white point, and the midway.

These three parameters each have an integer input of [0, 255] for their respective mapping. The colorize function creates an image and returns it.

from PIL import ImageOps, Image
img = Image.open('pic1.jpg')
img2 = ImageOps.colorize(img, black="red", white="white", mid="yellow")
img2.show()
ImageOps Colorize
ImageOps Colorize

Invert Function Using Python Pillow

This function is used to negate a picture by inverting it. The invert function, for example, accepts a single picture input and produces an inverted image.

from PIL import ImageOps, Image
img = Image.open('pic1.jpg')
img2 = ImageOps.invert(img)
img2.show()
ImageOps Invert
ImageOps Invert

Polorize Function

This function reduces the number of bits in each color channel. It requires two arguments. The first input is the picture, and the second parameter is bits, which maintains track of the number of bits in each channel.

from PIL import ImageOps, Image
img = Image.open('pic1.jpg')
img2 = ImageOps.posterize(img, 3)
img2.show()
ImageOps Polorize
ImageOps Polorize

Conclusion

Congratulations! You just learned about ImageOps Module in Pillow. Hope you enjoyed it! 😇

Liked the tutorial? In any case, I would recommend you to have a look at the tutorials mentioned below:

  1. The xlrd Module – How To Handle Excel Files In Python?
  2. Python Yagmail Module – An easy way to have emails sent!
  3. The pyzbar module: Decoding Barcodes in Python

Thank you for taking your time out! Hope you learned something new!! 😄