Let us see how to find the resolution of an image in Python. We will be solving this problem with two different libraries which are present in Python:
In our examples we will be using the following image:
The resolution of the above image is 600×135.
We will be using a library named Pillow to find the size(resolution) of the image. We will be using the function PIL.Image.open() to open and read our image and store the size in two variables by using the function img.size.
We will import OpenCV by importing the library cv2. We will load the image using the cv2.imread() function. After this, the dimensions can be found using the shape attribute. shape will give us the height and shape will give us the width.
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.