O'Reilly logo

Computer Vision with Python 3 by Saurabh Kapur

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Geometrical transformation

There are times when you need to perform different types of transformations to images such as resize, rotate, and flip. Pillow provides direct functions to perform these transformations, saving you from having to write the code from scratch:

  • Resize: To resize an image, use the resize() function, which takes a tuple of the new size as an argument:
        >>> from PIL import Image        >>> resize_img = img.resize((200,200))        >>> resize_img.show()
  • Rotate: To rotate an image, use the rotate() function, which takes in the degrees to be rotated (counter clockwise) as an argument:
        >>> from PIL import Image        >>> rotate_img = img.rotate(90)        >>> rotate_img.show()

The result of the preceding code is shown in the following image:

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required