How you can rotate a image using python?
Its Quite simple, In this tutorial we are going to use two image processing library to rotate image in Python
- PIL
- Open-Cv and Imutils
About PIL
It is a Python Image Library that add image processing capabilities to python interpreter. This Module is Developed By Fredrick Lundh. This Library support multiple file formats and have powerful image processing Capabilities.
Read More At: Pillow Documentation
About Open-Cv and Imutils
Open-Cv: It is a Open source python library that is used for machine
learning, image processing and many more. It supports wide variety of
languages such as C++,java and python etc. By using this module you can
detect faces, process images and objects etc.
Read More At: Open-Cv Documentation
Imutils: Open-Cv works with a Image Processing Tool that is Imutils.
Imutils provide series of image processing functions like translation,
rotation, resizing an etc.
Read More At: Imutils
Installation
To Install Pillow
pip install pillow
To Install Open-Cv
pip install opencv-python
To Install Imutils
pip install imutils
Source code
Method 1: By using Open-cv and Imutils
import cv2
import imutils
image=cv2.imread("Image PATH")
rotated_image=imutils.rotate(image,angle=45)
cv2.imshow("Image Rotation",rotated_image)
cv2.waitKey(0)
Method 2: By using Pillow
from PIL import Image
image=Image.open("IMAGE PATH")
rotated_image=image.rotate(45)
#Another Way
rotated_image1=image.transpose(Image.ROTATE_90)
rotated_image1.show()
0 Comments