{"id":12372,"date":"2021-10-01T11:00:15","date_gmt":"2021-10-01T05:30:15","guid":{"rendered":"https:\/\/python-programs.com\/?p=12372"},"modified":"2021-11-22T18:39:29","modified_gmt":"2021-11-22T13:09:29","slug":"rotate-an-image-by-an-angle-in-python","status":"publish","type":"post","link":"https:\/\/python-programs.com\/rotate-an-image-by-an-angle-in-python\/","title":{"rendered":"Rotate an Image by an Angle in Python"},"content":{"rendered":"
Don’t miss the chance of Java programs examples with output pdf free download<\/a> as it is very essential for all beginners to experienced programmers for cracking the interviews.<\/p>\n In this tutorial, we’ll look at how to rotate a picture by an angle in Python.<\/p>\n When we say that a picture has been rotated, we indicate that the image has been rotated to a specific degree by its centre.<\/p>\n Below are the ways to Rotate an Image by an Angle in Python.<\/p>\n PIL (Python Image Library) is a module that includes built-in functions for manipulating and working with images as input to the functions.<\/p>\n PIL has a built-in image.rotate(angle) method to rotate an image by an angle.<\/p>\n Syntax:<\/strong><\/p>\n image.rotate(angle)<\/p><\/blockquote>\n To load an image or give an image to the rotate() method, use the following code :<\/p>\n Image. open ( r” Path of the image ” )<\/p><\/blockquote>\n To display the image, we’ll need to use the code below:<\/p>\n image.show()<\/p><\/blockquote>\n Below is the Implementation:<\/strong><\/p>\n Before Rotation:<\/strong><\/p>\n <\/p>\n After Rotation:<\/strong><\/p>\n <\/p>\n OpenCV:<\/strong><\/p>\n OpenCV is a large open-source library for computer vision, machine learning, and image processing, and it currently plays a significant part in real-time operation, which is critical in today’s systems. It can process photos and movies to recognize items, faces, and even human handwriting. Python can process the OpenCV array structure for analysis when combined with other libraries such as NumPy. We employ vector space and execute mathematical operations on these features to identify visual patterns and their various features.<\/p>\n It has a variety of built-in capabilities for dealing with user-supplied photos.<\/p>\n To alter and work with images, OpenCV works brilliantly with another image processing library called imutils.<\/p>\n In Python, the imutils.rotate()<\/strong> function is used to rotate an image by an angle.<\/p>\n imutils.rotate(image, angle=angle)<\/p><\/blockquote>\n Syntax\u00a0<\/strong> For Reading Image using OpenCV<\/p>\n cv2.imread(r”Path of the image”)<\/p><\/blockquote>\n Syntax\u00a0<\/strong> to display the image using OpenCV<\/p>\n cv2.imshow(“output message”,imagevariable)<\/p><\/blockquote>\n Below is the implementation:<\/strong><\/p>\n Before Rotation:<\/strong><\/p>\n <\/p>\n After Rotation:<\/strong><\/p>\n Don’t miss the chance of Java programs examples with output pdf free download as it is very essential for all beginners to experienced programmers for cracking the interviews. In this tutorial, we’ll look at how to rotate a picture by an angle in Python. When we say that a picture has been rotated, we indicate …<\/p>\nRotate an Image by an Angle in Python<\/h2>\n
\n
Method #1: Using Python Image Library(PIL)<\/h3>\n
#importing image from PIL\r\nfrom PIL import Image \r\n \r\n#open the image by providing the image Path\r\nimge = Image.open(r\"D:\\repeat\\matrix.jpg\") \r\n#Rotating Image by 145 degrees\r\nrotate_imge= imge.rotate(145)\r\n#Displaying the image\r\nrotate_imge.show()<\/pre>\n
Method #2: Using OpenCV<\/h3>\n
#importing opencv and imutils \r\nimport cv2\r\nimport imutils\r\n\r\n#open the image by providing the image Path\r\nimge = cv2.imread(r\"D:\\repeat\\BTechGeeks (100).png\")\r\n #Rotating Image by 145 degrees\r\nrotate_imge = imutils.rotate(imge, angle=145)\r\n#Displaying the image\r\ncv2.imshow(\"Rotated Image\", rotate_imge)\r\ncv2.waitKey(0)<\/pre>\n
\nRelated Programs<\/strong>:<\/p>\n\n