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