Let us see how to calculate the area of an image in Python using Matplotlib.
Algorithm:
- Import the matplotlib.pyplot module.
- Import an image using the imread() method.
- Use the shape attribute of the image to get the height and width of the image. It fetches the number of channels in the image.
- Calculate the area as, area = height * width.
- Display the area.
Example 1: Consider the following image :

“GFG.jpg”
Python3
import matplotlib.pyplot as plt
img = plt.imread( "GFG.jpg" )
height, width, _ = img.shape
area = height * width
print ( "Area of the image is : " , area)
|
Output :
Area of the image is : 50244
Example 2: Consider the following image :

“image.jpg”
Python3
import matplotlib.pyplot as plt
img = plt.imread( "image.jpg" )
height, width, _ = img.shape
area = height * width
print ( "Area of the image is : " , area)
|
Output :
Area of the image is : 213200
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape,
GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out -
check it out now!
Last Updated :
31 Jul, 2021
Like Article
Save Article