An opening operation performs an erosion followed by a dilation using the same structuring element (or kernel) for both operations. In this way, erosion can be applied to eliminate small groups of undesirable pixels (for example, salt-and-pepper noise).
Erosion will affect all regions of the image indiscriminately. By performing a dilation operation after the erosion, we will reduce some of these effects. You can see the details of this operation in the following code:
opening = cv2.morphologyEx(image, cv2.MORPH_OPEN, kernel)