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

Savvy Sahai

Data Science Intern, Capgemini
linkedin profile url

As a student looking to break into the field of data engineering and data science, one can get really confused as to which path to take. Very few ways to do it are Google, YouTube, etc. I was one of... Read More

Relevant Projects

Multi-Class Text Classification with Deep Learning using BERT
In this deep learning project, you will implement one of the most popular state of the art Transformer models, BERT for Multi-Class Text Classification

Build an Image Classifier for Plant Species Identification
In this machine learning project, we will use binary leaf images and extracted features, including shape, margin, and texture to accurately identify plant species using different benchmark classification techniques.

Langchain Project for Customer Support App in Python
In this LLM Project, you will learn how to enhance customer support interactions through Large Language Models (LLMs), enabling intelligent, context-aware responses. This Langchain project aims to seamlessly integrate LLM technology with databases, PDF knowledge bases, and audio processing agents to create a comprehensive customer support application.

PyTorch Project to Build a GAN Model on MNIST Dataset
In this deep learning project, you will learn how to build a GAN Model on MNIST Dataset for generating new images of handwritten digits.

Time Series Forecasting with LSTM Neural Network Python
Deep Learning Project- Learn to apply deep learning paradigm to forecast univariate time series data.

A/B Testing Approach for Comparing Performance of ML Models
The objective of this project is to compare the performance of BERT and DistilBERT models for building an efficient Question and Answering system. Using A/B testing approach, we explore the effectiveness and efficiency of both models and determine which one is better suited for Q&A tasks.

Build an AI Chatbot from Scratch using Keras Sequential Model
In this NLP Project, you will learn how to build an AI Chatbot from Scratch using Keras Sequential Model.

OpenCV Project to Master Advanced Computer Vision Concepts
In this OpenCV project, you will learn to implement advanced computer vision concepts and algorithms in OpenCV library using Python.

Census Income Data Set Project-Predict Adult Census Income
Use the Adult Income dataset to predict whether income exceeds 50K yr based oncensus data.

Build an End-to-End AWS SageMaker Classification Model
MLOps on AWS SageMaker -Learn to Build an End-to-End Classification Model on SageMaker to predict a patient’s cause of death.