The opening operation and closing operation process erosion and expansion in a certain order. But the two are not reversible, that is, the original image cannot be obtained after opening and closing first.
- open operation
The opening operation is to corrode first and then expand, and its function is to separate objects and eliminate small areas. Features: Eliminate noise and remove small interference blocks without affecting the original image.
- Close operation
The closing operation is the opposite of the opening operation. It expands first and then corrodes. Its function is to eliminate/"close" the holes in the object. Features: it can fill the closed area
API:
Cv.morphologyEx(img,op,kernel)
Parameters: img: the image to process
Op: Processing method: if the open operation is performed, it is set to cv.MORPH_OPEN, and if the closed operation is performed, it is set to cv.MORPH_COLOSE
Kernel: nuclear structure
Example: