Morphological Operations on Images
Python OpenCV Morphological operations are one of the Image processing techniques that process images based on shape. This processing strategy is usually performed on binary images.
Operation |
Purpose |
---|---|
erode(image, kernel, iterations=1) | Erosion primarily involves eroding the outer surface (the foreground) of the image. As binary images only contain two pixels 0 and 255, it primarily involves eroding the foreground of the image and it is suggested to have the foreground as white. |
dilate(image, kernel, iterations=1) | Dilation involves dilating the outer surface (the foreground) of the image. As binary images only contain two pixels 0 and 255, it primarily involves expanding the foreground of the image and it is suggested to have the foreground as white. |
morphologyEx(image, Morphology_method, kernel, iterations=1) |
Some of the morphology methods are shown below:
|
Erosion
Erosion primarily involves eroding the outer surface (the foreground) of the image. As binary images only contain two pixels 0 and 255, it primarily involves eroding the foreground of the image and it is suggested to have the foreground as white.
cv2.erode(image, kernel, iterations=1)
Dilation
Dilation involves dilating the outer surface (the foreground) of the image. As binary images only contain two pixels 0 and 255, it primarily involves expanding the foreground of the image and it is suggested to have the foreground as white.
cv2.dilate(image, kernel, iterations=1)
Opening
The opening involves erosion followed by dilation in the outer surface (the foreground) of the image. It is generally used to remove the noise in the image.
cv2.morphologyEx(image, cv2.MORPH_OPEN, kernel, iterations=1)
Closing
Closing involves dilation followed by erosion in the outer surface (the foreground) of the image. It is generally used to remove the noise in the image.
cv2.morphologyEx(image, cv2.MORPH_CLOSE, kernel, iterations=1)
Morphological Gradient
The morphological gradient first applies erosion and dilation individually on the image and then computes the difference between the eroded and dilated image. The output will be an outline of the given image.
cv2.morphologyEx(image, cv2.MORPH_GRADIENT, kernel)
Top Hat
Top Hat is yet another morphological operation where an Opening is performed on the binary image and the output of this operation is a difference between the input image and the opened image.
cv2.morphologyEx(image, cv2.MORPH_TOPHAT, kernel)
Black Hat
The Black Hat enhances dark objects of interest on a bright background. The output of this operation is the difference between the closing of the input image and the input image.
cv2.morphologyEx(image, cv2.MORPH_BLACKHAT, kernel)
Python OpenCV Cheat Sheet
The Python OpenCV Cheat Sheet is your complete guide to mastering computer vision and image processing using Python. It’s designed to be your trusty companion, helping you quickly understand the important ideas, functions, and techniques in the OpenCV library. Whether you’re an experienced developer needing a quick reminder or a newcomer excited to start, this cheat sheet has got you covered.
In this article, we’ve gathered all the vital OpenCV concepts and explained them in simple terms. We’ve also provided practical examples to make things even clearer. You’ll learn everything from how to handle images to using advanced filters, spotting objects, and even exploring facial recognition. It’s all here to help you on your journey of discovering the amazing world of computer vision.
Table of Content
- Python OpenCV Cheat Sheet 2023
- Core Operations
- Drawing Shapes and Text on Images
- Arithmetic Operations on Images
- Morphological Operations on Images
- Geometric Transformations on Image
- Image Thresholding
- Edge/Line Detection (Features)
- Image Pyramids
- Changing the Colorspace of Images
- Smoothing Images
- Working With Videos
- Camera Calibration and 3D Reconstruction
Contact Us