 
  Data Structure Data Structure
 Networking Networking
 RDBMS RDBMS
 Operating System Operating System
 Java Java
 MS Excel MS Excel
 iOS iOS
 HTML HTML
 CSS CSS
 Android Android
 Python Python
 C Programming C Programming
 C++ C++
 C# C#
 MongoDB MongoDB
 MySQL MySQL
 Javascript Javascript
 PHP PHP
- 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
 