- 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 white TopHat operation on images using OpenCV
In this program, we will perform the TopHat operation on images. TopHat operation is a morphological operation that is used to extract small elements and details from given images. TopHat is used to enhance bright objects in a dark background. We will use the morphologyEx(image, cv2.MORPH_TOPHAT, kernel) function
Original Image
Algorithm
Step 1: Import cv2. Step 2: Read the image. Step 3: Define the kernel size. Step 4: Pass the image and kernel to the cv2.morphologyex() function. Step 5: Display the output.
Example Code
import cv2 image = cv2.imread('tophat.jpg') filter_size = (5,5) kernel = cv2.getStructuringElement(cv2.MORPH_RECT, filter_size) image = cv2.morphologyEx(image, cv2.MORPH_TOPHAT, kernel) cv2.imshow('TopHat', image)
Output
Explanation
As you can see, the small details are enhanced. TopHat transform is useful in obtaining the minor details from the input image.
- Related Articles
- Performing white BlackHat operation on images using OpenCV
- Performing an opening operation on an image using OpenCV
- Performing a closing operation on an image using OpenCV
- How to perform Bitwise Not operation on images using Java OpenCV?
- How to perform Bitwise OR operation on two images using Java OpenCV?
- How to perform Bitwise XOR operation on two images using Java OpenCV?
- How to perform Bitwise And operation on two images using Java OpenCV?
- How to perform bitwise XOR operation on images in OpenCV Python?
- Performing binary thresholding on an image using OpenCV
- Performing truncate thresholding on an image using OpenCV
- Performing zero thresholding on an image using OpenCV
- How to perform bitwise AND operation on two images in OpenCV Python?
- How to perform bitwise OR operation on two images in OpenCV Python?
- Performing inverse binary thresholding on an image using OpenCV
- Performing inverse zero thresholding on an image using OpenCV

Advertisements