Erosion and dilation in images I don't know if I am posting in the correct place. I wanted to ask about dilation and erosion in bitmaps. I have as a homework to implement in a programming language these morphological operations but I fail in understanding how they work. I know that erosion will shrink an object and dilation will enlarge it.

For example I have
$$A=\matrix{0 &amp;1 &amp;0 &amp;1 &amp; 1\\
0 &amp;1 &amp;0 &amp;1 &amp; 0\\
0 &amp;1 &amp;1 &amp;1 &amp; 0\\
0 &amp;1 &amp;1 &amp;0 &amp; 0\\
0 &amp;1 &amp;1 &amp;1 &amp; 0},\; 
se=\matrix{1 &amp;0 &amp;0\\
1 &amp;1 &amp;0\\
0 &amp;0 &amp;1}$$

What would be the eroded and dilated output and how to compute it step by step?
Here's a step-by-step procedure for erosion/dilation by hand:


Print out A and se on two sheets of paper
Place the se paper on every pixel of the A sheet in turn
At each position: Take the pixel values of A at the respective positions where se is 1. For the first top-left position, this would be 0,0,1,1 as I have tried to illustrate here:
For an erosion, the result for the current pixel is the logical AND of the values you just wrote down. For dilation it is logical OR. (Or min/max for grayvalue images)


Note: You will either get a result image that is smaller than A or you have to add "padding" pixels to A (typically 1 for erosion and 0 for dilation)