- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Downsampling an image using OpenCV
In this program, we will down sample an image. Downsampling is decreasing the spatial resolution while keeping the 2D representation of an image. It is typically used for zooming out of an image. We will use the pyrdown() function in the openCV library to complete this task.
Original Image
Algorithm
Step 1: Fead the image. Step 2: Pass the image as a parameter to the pyrdown() function. Step 3: Display the output.
Example Code
import cv2 image = cv2.imread('testimage.jpg') print("Size of image before pyrDown: ", image.shape) image = cv2.pyrDown(image) print("Size of image after pyrDown: ", image.shape) cv2.imshow('DownSample', image)
Output
Size of image before pyrDown: (350, 700, 3) Size of image after pyrDown: (175, 350, 3)
Explanation
If we observe the size of the image before and after using the pyrDown function, we see that the size is decreased, i.e., we have downsampled the image.
- Related Articles
- Upsampling an image using OpenCV
- Draw an ellipse on an image using OpenCV
- Reading an image using Python OpenCv module
- Cartooning an Image using OpenCV in Python?
- Detecting contours in an image using OpenCV
- Drawing borders around an image using OpenCV
- Draw rectangle on an image using OpenCV
- Performing an opening operation on an image using OpenCV
- Performing binary thresholding on an image using OpenCV
- Performing truncate thresholding on an image using OpenCV
- Performing zero thresholding on an image using OpenCV
- Draw a line on an image using OpenCV
- Blurring an image using the OpenCV function blur()
- Blurring an image using the OpenCV function medianBlur()
- Eroding an image using the OpenCV function erode()

Advertisements