Morphology mainly extracts component information from images, which is usually of great significance to express and describe the shape of images, and is usually the most essential shape feature used in image understanding.
For example, when recognizing handwritten numbers, skeleton information can be obtained through morphological operation, and when recognizing details, only skeleton can be calculated. Morphological processing has very important applications in visual inspection, character recognition, medical image processing, image compression coding and other fields.
Morphological operations mainly include:
Corrosion operation and expansion operation are the basis of morphological operation. By combining corrosion operation and expansion operation, different forms of operations such as open operation, closed operation, morphological gradient operation, top hat operation, black hat operation, hit and miss operation can be realized.
Corrosion is one of the most basic morphological operations, which can eliminate the boundary points of the image, make the image shrink inward along the boundary, and remove the parts smaller than the specified structural elements.
Corrosion is used to "shrink" or "refine" the foreground in binary images, thus achieving functions such as denoising and element segmentation. For example, Figure 8- 1, the original figure on the left and the etching result on the right.
In the etching process, structural elements are usually used to scan the image to be etched pixel by pixel, and the etching result is determined according to the relationship between structural elements and the etched image.
In OpenCV, the function cv2.erode () is used to realize the corrosion operation, and its syntax format is:
Among them:
Example 8.2 Use the function cv2.erode () to complete image erosion.