Morphological Examples¶
[22]:
from easycv import Image
from easycv.transforms import Noise, Erode, Dilate, Morphology
For this example we will load an example image from the images folder. For more examples of image loading check Image examples.
[23]:
img = Image("images/logo.png")
img
[23]:
Erode¶
Erosion on an image works like soil erosion, it erodes away the boundaries of objects. For more information check the reference.
[24]:
img.apply(Erode())
[24]:
Dilate¶
Dilation is the opposite of erosion. For more information check the reference.
[25]:
img.apply(Dilate())
[25]:
Morphology¶
We can apply different morphological operations through the various methods of Morphology. For more information check the reference.
Let’s apply some salt noise to the image
[26]:
noisy = img.apply(Noise(method="salt"))
noisy
[26]:
Morphology opening method is very good at removing small random noises like this. Let’s apply it to clean the image.
[27]:
noisy.apply(Morphology(method="opening"))
[27]:
Let’s apply some pepper noise to the image
[28]:
noisy = img.apply(Noise(method="pepper", amount=0.2))
noisy
[28]:
Morphology closing method is very good at removing small random noises like this. Let’s apply it to clean the image.
[29]:
noisy.apply(Morphology(method="closing"))
[29]:
We can also compute things like TopHat (difference between input image and Opening of the image) and BlackHat (difference between the closing of the input image and input image).
[30]:
img.apply(Morphology(method="tophat", size=9))
[30]:
[31]:
img.apply(Morphology(method="blackhat", size=9))
[31]: