import cv2 import numpy as np file_name = 'area1.png' img = cv2.imread(file_name) kernel = np.ones((1,1), np.uint8) opening = img i = 0 while i < 5: opening = cv2.morphologyEx(opening, cv2.MORPH_CLOSE, kernel) i = i + 1 kernel = np.ones((1,1), np.uint8) opening = cv2.erode(opening, kernel, iterations = 1) cv2.imwrite('marea.png', opening)