Python | Morphological Operations in Image Processing (Gradient) | Set-3
In the previous articles, the Opening operation and the Closing operations were specified. In this article, another morphological operation is elaborated that is Gradient. It is used for generating the outline of the image. There are two types of gradients, internal and external gradient. The internal gradient enhances the internal boundaries of objects brighter than their background and external boundaries of objects darker than their background. For binary images, the internal gradient generates a mask of the internal boundaries of the foreground image objects.
Syntax: cv2.morphologyEx(image, cv2.MORPH_GRADIENT, kernel)
-> image: Input Image array.
-> cv2.MORPH_GRADIENT: Applying the Morphological Gradient operation.
-> kernel: Structuring element.
Below is the Python code explaining Gradient Morphological Operation –
The output image frame shows the outline generated over the blue book and the blue object in top left.