In the previous articles, the opening and closing operations were specified. In this article, another morphological operation has been developed — gradient . It is used to generate the outline of an image. There are two types of gradients, inner and outer gradient. Inner gradient makes the inner edges of objects brighter than their background, and the outer edges of objects are darker than their background. For binary images, the inner gradient creates a mask of the inner borders of foreground image objects.
Syntax: cv2.morphologyEx (image, cv2.MORPH_GRADIENT, kernel)
– & gt; image : Input Image array.
– & gt; cv2.MORPH_GRADIENT : Applying the Morphological Gradient operation.
– & gt; kernel : Structuring element.
Below is the Python code explaining the gradient of the morphological operation —
Frame of the output the image shows the outline created over the blue book and the blue ob object in the upper left corner.