Image opening is somewhat comparable to erosion. It is being applied to remove foreground pixels from the edges; however, it is less effective than erosion, in general.
Image opening is targeted at keeping foreground regions that have a similar shape to the structuring element or that can fully contain the structuring element while eliminating all other areas of foreground pixels.
To illustrate how it works in practice, we will use this image with geometrical figures and see how the opening is different than erosion:
Let's get to the coding part and apply the opening function to the preceding image:
using Images, ImageView, ImageMorphology
geom_img = load("sample-images/geometrical-figures-and-noise.jpg");
geom_img_binary = Gray.(1 * Gray.(geom_img) .> 0.5);
geom_img_binary_o = opening(geom_img_binary)
imshow(geom_img_binary_e)
If you compare the results generated by opening and erode functions, you will see that opening (first image) has kept the large object untouched, and it has removed the small dots, when, at the same time, erode (second image) has reduced the size of all of the objects.
This is the first image:
This is the second image: