Morphological operations — it is a set of operations that process shape-based images. They apply a structuring element to an input image and generate an output image.
The main morphological operations are two: erosion and dilatation
Basics of erosion:
- Blurs the boundaries of the foreground object li>
- Used to reduce image capabilities.
- Kernel (matrix of odd size (3 , 5,7) collapsed with the image.
- A pixel in the original image (either 1 or 0) will be counted as 1 only if all pixels under the kernel are equal to 1, otherwise it is blurred (zeroed out). li>
- Thus, all pixels near the border will be discarded depending on the size of the kernel.
- Thus, the thickness or size of the foreground object is reduced or just the white area is reduced in the image.
Basics of dilatation:
- Increases the area of the object
- Used to accentuate functions
- Core (matrix of odd size (3 , 5,7) collapsed with the image
- The pixel element in the original image is “1” if at least one pixel under the kernel is “1”.
- Increases the white area in the image or increases the size of the foreground object
numpy as np
cv2.erode (img, kernel, iterations
1 code >
cv2.dilate (img, kernel, iterations
cv2. imshow (
The second image is a blurred shape of the original image, and the third image is an extended form. < br />
Using erosion and dilatation:
- This is useful for removing small white noise.
- Used for detaching two related objects, etc.
- Stretching :
- In cases such as noise removal, erosion is followed by expansion. Because erosion removes white noise, but it also reduces our subject. So we are expanding it. Since the noise has disappeared, they will not come back, but our object area increases.
- This is also useful when connecting broken parts of an object.
article courtesy of Pratima Upadhyay . If you are as Python.Engineering and would like to contribute, you can also write an article using contribute.python.engineering or by posting an article contribute @ python.engineering. See my article appearing on the Python.Engineering homepage and help other geeks.
Please post comments if you find anything wrong or if you would like to share more information on the topic discussed above.