What are image pyramids How does a Gaussian pyramid work

This recipe explains what are image pyramids and how does a Gaussian pyramid work

Recipe Objective: What are image pyramids? How does a Gaussian pyramid work?

In this recipe, let us understand what image pyramids are and how they are helpful.

Getting Started with Image Segmentation using Mask R-CNN

Step 1: Import the libraries and read the image.

Let us first import the necessary libraries and read the image. The image that we are using here is the one shown below.

Input Image

import numpy as np
import cv2
image = cv2.imread('edgeflower.jpg')

Step 2: Image Pyramids

Image pyramids are highly useful in obtaining copies of the same image in different resolutions. You might wonder why do we need additional copies of the same image in different resolutions. Well, on some occasions, when we try to detect a face or any other object in the image, we might not know the exact size of the face or object we are looking for. Image pyramids come to aid in such situations. There are two ways of creating image pyramids. They are :

  1. Gaussian Pyramids
  2. Laplacian Pyramids

Let us discuss what Gaussian pyramids are and how we can create a Gaussian pyramid. Gaussian pyramids are very simple. They use the gaussian average to scale down an image from high resolution to lower resolution. Thus we obtain an M/2 x N/2 image if the size of the original image is M x N. The same method is applied while we go upper in the pyramid.

The cv2.pyrDown() and cv2.pyrUp() functions can be used to find the Gaussian pyramids.

lr1 = cv2.pyrDown(image)
lr2 = cv2.pyrDown(lr1)
hr1 = cv2.pyrUp(lr2)
hr2 = cv2.pyrUp(lr1)

Step 3: Displaying the image

Let us display the image using cv2.imshow() function. cv2.imshow('Original Image', image)
cv2.imshow('Lower resolution 1', lr1)
cv2.imshow('Lower resolution 2', lr2)
cv2.waitKey(0)
cv2.destroyAllWindows()

Output:

PyrDown

cv2.imshow('Higher resolution 1', hr1)
cv2.imshow('Higher resolution 2', hr2)
cv2.waitKey(0)
cv2.destroyAllWindows()

Output:

PyrUp

What Users are saying..

profile image

Ray han

Tech Leader | Stanford / Yale University
linkedin profile url

I think that they are fantastic. I attended Yale and Stanford and have worked at Honeywell,Oracle, and Arthur Andersen(Accenture) in the US. I have taken Big Data and Hadoop,NoSQL, Spark, Hadoop... Read More

Relevant Projects

AWS MLOps Project for Gaussian Process Time Series Modeling
MLOps Project to Build and Deploy a Gaussian Process Time Series Model in Python on AWS

Time Series Project to Build a Multiple Linear Regression Model
Learn to build a Multiple linear regression model in Python on Time Series Data

Personalized Medicine: Redefining Cancer Treatment
In this Personalized Medicine Machine Learning Project you will learn to classify genetic mutations on the basis of medical literature into 9 classes.

NLP Project on LDA Topic Modelling Python using RACE Dataset
Use the RACE dataset to extract a dominant topic from each document and perform LDA topic modeling in python.

Time Series Analysis with Facebook Prophet Python and Cesium
Time Series Analysis Project - Use the Facebook Prophet and Cesium Open Source Library for Time Series Forecasting in Python

Topic modelling using Kmeans clustering to group customer reviews
In this Kmeans clustering machine learning project, you will perform topic modelling in order to group customer reviews based on recurring patterns.

MLOps AWS Project on Topic Modeling using Gunicorn Flask
In this project we will see the end-to-end machine learning development process to design, build and manage reproducible, testable, and evolvable machine learning models by using AWS

AWS MLOps Project to Deploy Multiple Linear Regression Model
Build and Deploy a Multiple Linear Regression Model in Python on AWS

Loan Eligibility Prediction Project using Machine learning on GCP
Loan Eligibility Prediction Project - Use SQL and Python to build a predictive model on GCP to determine whether an application requesting loan is eligible or not.

Build CNN for Image Colorization using Deep Transfer Learning
Image Processing Project -Train a model for colorization to make grayscale images colorful using convolutional autoencoders.