- 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
Dilating images using the OpenCV function dilate()
In this program, we will dilate an image using the dilate function in the OpenCV library. Dilation adds pixels to the boundaries of objects in an image, i.e., it expands the image on all sides.
Original Image
Algorithm
Step 1: Import cv2 and numpy. Step 2: Read the image using opencv.imread(). Step 3: Define the kernel using np.ones() function. Step 4: Pass the image and kernel to the dilate() function. Step 5: Display the image
Example Code
import cv2 import numpy as np image = cv2.imread('testimage.jpg') kernel = np.ones((3,3), np.uint8) image = cv2.dilate(image, kernel) cv2.imshow('Dilated Image', image)
Output
Explanation
As you can see, the image is expanded, i.e., the pixels of the image are expanded and hence, the image looks a bit distorted.
Advertisements