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 &1 &0 &1 & 1\\ 0 &1 &0 &1 & 0\\ 0 &1 &1 &1 & 0\\ 0 &1 &1 &0 & 0\\ 0 &1 &1 &1 & 0},\; se=\matrix{1 &0 &0\\ 1 &1 &0\\ 0 &0 &1}$$

What would be the eroded and dilated output and how to compute it step by step?

  • $\begingroup$ Did you read this? mathworks.com/help/toolbox/images/f18-12508.html $\endgroup$
    – leonbloy
    Feb 16, 2012 at 0:50
  • $\begingroup$ @leonbloy yes I read it but I used matlab to see if I did it correctly and apparently I did not. $\endgroup$
    – omg_img
    Feb 16, 2012 at 1:13
  • $\begingroup$ @J.M. Yes I thought so but then I took a look at the faq and it didn't seem right to post the question there. $\endgroup$
    – omg_img
    Feb 16, 2012 at 1:25
  • $\begingroup$ Basically, the implementation of dilation and erosion follow their definition quite close. Some make sure that you really understood these definitions. (By the way: Can you calculate the outcome of your example by hand?) One point which have to be considered in addition to the definition is the boundary treatment. Most often this is done by extending the image $A$ over the boundary as far as needed (e.g. in a symmetric way) and apply erosion and dilation only the "inner pixels" of the extended image. $\endgroup$
    – Dirk
    Feb 16, 2012 at 7:19
  • 1
    $\begingroup$ @Dirk I am trying to do it by hand first. I am failing at this point. This is why I am asking for a step by step example. $\endgroup$
    – omg_img
    Feb 16, 2012 at 8:55

1 Answer 1


Here's a step-by-step procedure for erosion/dilation by hand:

  1. Print out A and se on two sheets of paper
  2. Place the se paper on every pixel of the A sheet in turn
  3. 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:enter image description here
  4. 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)

  • $\begingroup$ Great answer! How did you create the picture? $\endgroup$
    – Phonon
    Feb 16, 2012 at 14:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.