Dilating images using the OpenCV function dilate()

OpenCVPythonServer Side ProgrammingProgramming

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.

Algorithm

Step 1: Import cv2 and numpy.
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

cv2.imshow('Dilated Image', image)