Morphological Filters
If you are new about image processing. First, we have to understand about filters, check out this site:
These filters are aimed at binary images, pixels values are 0 and 1 which is black and white color. Binary images can be achieved from grayscale images by threshold image processing methods. The morphological filters can rounded off such as fill the holes of a certain size and remove the single dots or lines.
Shrink and Let Grow
the first point we want to round off larger image structure and remove the smaller structures in the binary image (to clean an image from noise or dirt). There is the idea of the methods to shrunk it and growing it back by the same amount.
- First, shrunk the structures of images by peeling off a layer
- Shrinking removes the smaller structures and left the larger structures
- Grown back by the same amount
Shrinking operation means to remove a layer of pixels from a foreground region around all its borders against the background. Growing operation means to adds a layer of pixels around the foreground region.
Basic Morphological Operations
Shrinking and growing are the two basic morphological operations that base on erosion and dilation. however, there are many general operations that goes well for removing or attaching single pixels and can perform much more complex operation. In this section, I will talk about 5 methods of this operation.
- The Structuring Element: using coefficient matrix H that the hot spot must its value be 1.
- Point Sets: it is helpful to describe binary images as sets of two-dimensional coordinate points.
- Dilation: the morphological operation that corresponds to the concept of growing
- Erosion: The quasi-inverse of dilation which is the concept of shrinking
Coding Section
in this section, we are going to coding morphological operation with openCV in googlecolab with python
Set up: download the file into googlecolab and then import the module that we are going to use.
from google.colab import files
uploaded = files.upload()import cv2
import numpy as np
from matplotlib import pyplot as plt
Dilation code
in OpenCV, it has a function for dilation image called “dilate” function and this is how to use it.
img = cv2.imread('Pic1.jpg', 0)kernel = np.ones((5,5),np.uint8)
dilation = cv2.dilate(img,kernel,iterations = 1)
Erosion code
similar to the dilation method. In OpenCV also has the function that called “erode” function
img = cv2.imread('Pic1.jpg', 0)kernel = np.ones((5,5),np.uint8)
erosion = cv2.erode(img,kernel,iterations = 1)
The application for morphological design is to implement erosion and dilation that depend on your work. I hope this article will help you to inspire your project in some way.