Rotation of Image is one of the simple Image transform operations that can be applied on an Image. By image rotation the image is rotated about its center by specified number of degrees. Image rotation is a specialization of affine transformation.
Image rotation results in some pixel values beyond image boundaries that is pixel values lying outside the dimension of the image. Such values will not be displayed in the output image shown. This happens when the number of degrees specified for Image rotation is not an integer multiple of 90 degrees.
Rotation using Python and Pillow:
The rotate() method of Python Image Processing Library Pillow takes number of degrees as a parameter and rotates the image in counter clockwise direction to the number of degrees specified.
Alternately, the transpose method can also be used with one of the constants Image.ROTATE_90, Image.ROTATE_180 and Image.ROTATE_270.
# import the Python Image processing Library
from PIL import Image
# Create an Image object from an Image
colorImage = Image.open("./effil.jpg")
# Rotate it by 45 degrees
rotated = colorImage.rotate(45)
# Rotate it by 90 degrees
transposed = colorImage.transpose(Image.ROTATE_90)
# Display the Original Image
# Display the Image rotated by 45 degrees
# Display the Image rotated by 90 degrees