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]:
../../_images/examples_transforms_morphological_3_0.png

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]:
../../_images/examples_transforms_morphological_6_0.png

Dilate

Dilation is the opposite of erosion. For more information check the reference.

[25]:
img.apply(Dilate())
[25]:
../../_images/examples_transforms_morphological_9_0.png

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]:
../../_images/examples_transforms_morphological_13_0.png

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]:
../../_images/examples_transforms_morphological_15_0.png

Let’s apply some pepper noise to the image

[28]:
noisy = img.apply(Noise(method="pepper", amount=0.2))
noisy
[28]:
../../_images/examples_transforms_morphological_17_0.png

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]:
../../_images/examples_transforms_morphological_19_0.png

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]:
../../_images/examples_transforms_morphological_21_0.png
[31]:
img.apply(Morphology(method="blackhat", size=9))
[31]:
../../_images/examples_transforms_morphological_22_0.png