- 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
Performing an opening operation on an image using OpenCV
In this program, we will perform the opening operation on image. Opening removes small objects from the foreground of an image, placing them in the background. This technique can also be used to find specific shapes in an image. Opening can be called erosion followed by dilation. The function we will use for this task is cv2.morphologyEx(image, cv2.MORPH_OPEN, kernel).
Original Image
Algorithm
Step 1: Import cv2 and numpy. Step 2: Read the image. Step 3: Define the kernel. Step 4: Pass the image and kernel to the cv2.morphologyex() function. Step 4: Display the output.
Example Code
import cv2 import numpy as np image = cv2.imread('testimage.jpg') kernel = np.ones((5,5), np.uint8) image = cv2.morphologyEx(image, cv2.MORPH_OPEN, kernel) cv2.imshow('Opening', image)
Output
- Related Articles
- Performing a closing 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
- Performing inverse binary thresholding on an image using OpenCV
- Performing inverse zero thresholding on an image using OpenCV
- Performing white TopHat operation on images using OpenCV
- Performing white BlackHat operation on images using OpenCV
- How to perform bilateral filter operation on an image in OpenCV using Python?
- Draw an ellipse on an image using OpenCV
- OpenCV Python – How to perform SQRBox filter operation on an image?
- OpenCV Python – How to perform bitwise NOT operation on an image?
- Draw rectangle on an image using OpenCV
- Draw a line on an image using OpenCV
- Upsampling an image using OpenCV

Advertisements