A morphological gradient operation is defined as the difference between the dilation and erosion of the input image: morph_gradient = cv2.morphologyEx(image, cv2.MORPH_GRADIENT, kernel)