

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Cropping an image using the Pillow library
<p>In this program, we will crop an image using the Pillow library. We will use the crop() function for the same. The function takes left, top, right, bottom pixel coordinates to crop the image.</p><h2>Original Image</h2><p><img src="https://www.tutorialspoint.com/assets/questions/media/49941/1.png" class="fr-fic fr-dib" width="600" height="293"></p><h2>Algorithm</h2><pre class="result notranslate">Step 1: Import Image from Pillow. Step 2: Read the image. Step 3: Crop the image using the crop function. Step 4: Display the output.</pre><h2>Example Code</h2><pre class="prettyprint notranslate">from PIL import Image im = Image.open('testimage.jpg') width, height = im.size left = 5 top = height / 2 right = 164 bottom = 3 * height / 2 im1 = im.crop((left, top, right, bottom)) im1.show()</pre><h2>Output</h2><p><img src="https://www.tutorialspoint.com/assets/questions/media/49941/69.png" class="fr-fic fr-dib" width="249" height="537"></p>
- Related Questions & Answers
- Rotating an image using Pillow library
- Loading and displaying an image using the Pillow library
- Applying MinFilter on an image using Pillow library
- Applying MaxFilter on an image using Pillow library
- Applying ModeFilter on an image using Pillow library
- Applying MedianFilter on an image using Pillow library
- Applying Gaussian Blur to an image using the Pillow library
- Applying Box Blur to an image using the Pillow library
- Applying rank filter to an image using the Pillow library
- Finding edges in an image using Pillow
- Calculating the median of all pixels for each band in an image using the Pillow library
- Calculating the mean of all pixels for each band in an image using the Pillow library
- Calculating the variance of all pixels for each band in an image using the Pillow library
- Calculating the standard deviation of all pixels for each band in an image using the Pillow library
- Calculating the root mean square of all pixels for each band in an image using the Pillow library
Advertisements