Loading the images via Pillow Library
Let us check for an image that is in the PNG or JPEG format. The image can be referred via its path. Image class is the heart of PIL. It has open() function which opens up an image and digital file format can be retrieved as well as pixel format.
Image Used:
Python3
from PIL import Image image = Image. open ( 'Sample.png' ) # summarize some details about the image print (image. format ) print (image.size) print (image.mode) |
Output :
PNG (400, 200) RGB
How to Convert images to NumPy array?
Images are an easier way to represent the working model. In Machine Learning, Python uses the image data in the format of Height, Width, Channel format. i.e. Images are converted into Numpy Array in Height, Width, Channel format. In this article we will see How to Convert images to NumPy array?
Modules Needed:
- NumPy: By default in higher versions of Python like 3.x onwards, NumPy is available and if not available(in lower versions), one can install by using
pip install numpy
- Pillow: This has to be explicitly installed in later versions too. It is a preferred image manipulation tool. In Python 3, Pillow python library which is nothing but the upgradation of PIL only. It can be installed using
pip install Pillow
Contact Us