# Downsampling an image using OpenCV

OpenCVPythonServer Side ProgrammingProgramming

#### OpenCV Complete Dummies Guide to Computer Vision with Python

70 Lectures 9 hours

#### Computer vision: OpenCV Fundamentals using Python

41 Lectures 4 hours

#### Python - OpenCV & PyQT5 together

51 Lectures 8 hours

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.

## 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

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.

Updated on 17-Mar-2021 08:28:17