The Wayback Machine - http://web.archive.org/web/20240118183140/https://www.geeksforgeeks.org/image-pyramid-using-opencv-python/
Open In App
Related Articles

Image Pyramid using OpenCV | Python

Improve
Improve
Improve
Like Article
Like
Save Article
Save
Report issue
Report

Image Pyramids are one of the most beautiful concept of image processing.Normally, we work with images with default resolution but many times we need to change the resolution (lower it) or resize the original image in that case image pyramids comes handy.

The pyrUp() function increases the size to double of its original size and pyrDown() function decreases the size to half. If we keep the original image as a base image and go on applying pyrDown function on it and keep the images in a vertical stack, it will look like a pyramid. The same is true for upscaling the original image by pyrUp function.
Image

Once we scale down and if we rescale it to the original size, we lose some information and the resolution of the new image is much lower than the original one.

Below is an example of Image Pyramiding –




import cv2
import matplotlib.pyplot as plt
  
img = cv2.imread("images/input.jpg")
  
layer = img.copy()
  
for i in range(4):
    plt.subplot(2, 2, i + 1)
  
    # using pyrDown() function
    layer = cv2.pyrDown(layer)
  
    plt.imshow(layer)
    cv2.imshow("str(i)", layer)
    cv2.waitKey(0)
      
  
cv2.destroyAllWindows()


Output:
Image

Advantages of Image pyramids:

  • Lowering of resolution
  • Getting various sizes of image
  • Image Blending
  • Edge detection
Don't miss your chance to ride the wave of the data revolution! Every industry is scaling new heights by tapping into the power of data. Sharpen your skills, become a part of the hottest trend in the 21st century.
Dive into the future of technology - explore the Complete Machine Learning and Data Science Program by GeeksforGeeks and stay ahead of the curve.

Commit to GfG's Three-90 Challenge! Purchase a course, complete 90% in 90 days, and save 90% cost click here to explore.
Last Updated : 04 Jan, 2023
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads
Complete Tutorials