![]() To fix this issue, you can crop the image to that part of the image that you want to highlight. This results in a photo where the focus of the image isn’t really front-and-center. When you are taking photographs, all too often the subject of the photo will move or you didn’t zoom in far enough. Now let’s discover how you can use Pillow to crop images! Cropping Images You can try passing in some of the other images included on Github to see different graphs or swap in some of your own images to see their histograms. This graph shows you the tonal values in the image that were mentioned earlier. When you run this code, you will see the following graph: The hist() function takes in the list of values and the number of equal-width bins in the range of values. Then you extract the histogram from it and pass the list of values to your Matplotlib object where you call the hist() function. When you run this code, you open the image as before. To see one way that you could do that, create a new file named get_histrogram.py and add this code to it: # get_histrogram.py Then you will use Matplotlib to graph it out. To get the histogram from this image you will use the image’s histogram() method. It shows you the brightness of the photo as a list of values that you could graph. The histogram of an image is a graphical representation of its tonal values. ![]() Try running this function on some of your own photos and see what kinds of information you can extract!Īnother fun bit of information that you can extract from the image is its histogram data. This can remove part or all of the Exif data. However, the Exif data can be altered if you use photo editing software to crop, apply filters or do other types of image manipulation. The timestamp for the photo is also in the Exif information. The output is pretty verbose, but you can learn from that data that this particular photo was taken with a Sony 6300 camera with the following settings: “E 18-200mm F3.5-6.3 OSS LE”. EXIF stands for “Exchangeable image file format” and is a standard that specifies the formats for images, sound, and ancillary tags used by digital cameras. Then you use the _getexif() method to get metadata about your image. Here you get the width and height of the image using the image object. Create a new file named get_image_info.py and add this code to it: # get_image_info.py You can use Pillow to learn more about your images as well. This is pretty handy because now you can view your images with Python without writing an entire graphical user interface. When you run this code, you will see a window similar to the following: This will return an object that you can use to learn more about your image. Then you use Image.open() to open up an image. Here you import Image from the PIL package. To see how this works, create a new file named open_image.py and enter the following code: # open_image.py The viewer is made with Tkinter and works in much the same way as Matplotlib does when it shows a graph. You can use Pillow to open and view any of the file types mentioned in the “fully supported formats” section at the link above. For a full listing of the image file types that Pillow supports, see the following: Pillow let’s you open and view many different file types. Now that Pillow is installed, you are ready to start using it! Opening Images Here is how you would do it after opening a terminal or console window: python -m pip install pillow Installing Pillow is easy to do with pip. Now let’s get started by installing Pillow! Installing Pillow They are included with the code examples on Github. The images used in this article are some that the author has taken himself. ![]() In this articla, you will learn how to do the following with Pillow:Īs you can see, Pillow can be used for many types of image processing. You can use Pillow for several use cases including the following: Several other Python packages, such as wxPython and ReportLab, use Pillow to support loading many different image file types. The current version of this software is in Pillow, which is a fork of the original PIL to support Python 3. It allows you to process photos and do many common image file manipulations. The Python Imaging Library (PIL) is a 3rd party Python package that adds image processing capabilities to your Python interpreter. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |