Steve on Image Processing

September 29th, 2008

Dilation algorithms—decomposing more shapes

In my previous post on dilation algorithms I discussed structuring element decomposition. We looked at the decomposition of structuring elements with rectangular domains. Today I want to follow up on the idea by looking at decompositions of other structuring element shapes.

The strel function offers a variety of flat structuring element shapes:

  • diamond
  • disk
  • line
  • octagon
  • pair
  • periodicline
  • rectangle
  • square

(The strel function also offers nonflat shapes, and shapes with arbitrary domains.)

Let's look at the 'diamond' shape. The doc says SE = strel('diamond', R) creates a flat, diamond-shaped structuring element, where R specifies the distance from the structuring element origin to the points of the diamond." For example:

se1 = strel('diamond', 5)
 
se1 =
 
Flat STREL object containing 61 neighbors.
Decomposition: 4 STREL objects containing a total of 17 neighbors

Neighborhood:
     0     0     0     0     0     1     0     0     0     0     0
     0     0     0     0     1     1     1     0     0     0     0
     0     0     0     1     1     1     1     1     0     0     0
     0     0     1     1     1     1     1     1     1     0     0
     0     1     1     1     1     1     1     1     1     1     0
     1     1     1     1     1     1     1     1     1     1     1
     0     1     1     1     1     1     1     1     1     1     0
     0     0     1     1     1     1     1     1     1     0     0
     0     0     0     1     1     1     1     1     0     0     0
     0     0     0     0     1     1     1     0     0     0     0
     0     0     0     0     0     1     0     0     0     0     0

 

The display says the structuring element has 61 neighbors in its domain, but the four decomposed structuring elements have a total of only 17 neighbors.

What shapes makes up the decomposition? We can use getsequence and getnhood to find out.

se1_seq = getsequence(se1);
for k = 1:numel(se1_seq)
    getnhood(se1_seq(k))
ans =

     0     1     0
     1     1     1
     0     1     0

ans =

     0     1     0
     1     0     1
     0     1     0

ans =

     0     0     1     0     0
     0     0     0     0     0
     1     0     0     0     1
     0     0     0     0     0
     0     0     1     0     0

ans =

     0     1     0
     1     0     1
     0     1     0

end

This decomposition comes from Rein van den Boomgard and Richard van Balen, "Methods for Fast Morphological Image Transforms Using Bitmapped Binary Images," Computer Vision, Graphics, and Image Processing: Models and Image Processing, vol. 54, no. 3, May 1992, pp. 252-254. (That journal name sure is a mouthful!)

Now let's look at the 'disk' structuring element. By default, strel('disk',R) actually gives you an approximation to a disk shape, where the approximation is based on a technique called radial decomposition using periodic lines. The reference sources are:

  • Rolf Adams, "Radial Decomposition of Discs and Spheres," Computer Vision, Graphics, and Image Processing: Graphical Models and Image Processing, vol. 55, no. 5, September 1993, pp. 325-332.
  • Ronald Jones and Pierre Soille, "Periodic lines: Definition, cascades, and application to granulometries," Pattern Recognition Letters, vol. 17, 1996, 1057-1063.
se2 = strel('disk', 5)
 
se2 =
 
Flat STREL object containing 69 neighbors.
Decomposition: 6 STREL objects containing a total of 18 neighbors

Neighborhood:
     0     0     1     1     1     1     1     0     0
     0     1     1     1     1     1     1     1     0
     1     1     1     1     1     1     1     1     1
     1     1     1     1     1     1     1     1     1
     1     1     1     1     1     1     1     1     1
     1     1     1     1     1     1     1     1     1
     1     1     1     1     1     1     1     1     1
     0     1     1     1     1     1     1     1     0
     0     0     1     1     1     1     1     0     0

 

Similar to the 'diamond' shape above, the 'disk' shape is decomposed into a sequence of smaller structuring elements:

se2_seq = getsequence(se2);
for k = 1:numel(se2_seq)
    getnhood(se2_seq(k))
ans =

     1
     1
     1

ans =

     1     0     0
     0     1     0
     0     0     1

ans =

     1     1     1

ans =

     0     0     1
     0     1     0
     1     0     0

ans =

     1     1     1

ans =

     1
     1
     1

end

I mentioned above that strel('disk',R) gives you an approximation to a disk. Let's see what that approximation looks like with a larger radius:

se3 = strel('disk', 21);
imshow(getnhood(se3), 'InitialMagnification', 'fit')

Well, that's definitely an approximation. It looks a lot more like an octagon than a circle. The syntax strel('disk',R,N) gives you more control over the approximation. N can be 0, 4, 6, or 8. The values 4, 6, and 8 indicate different levels of approximation. The default value is 4. With N equal to 8, the result looks closer to a circle, but dilation is a little slower because the decomposition isn't as efficient.

se4 = strel('disk', 21, 8);
imshow(getnhood(se4), 'InitialMagnification', 'fit')

Setting N = 0 asks strel to construct a disk shape with no decomposition approximation.

se5 = strel('disk', 21, 0);
imshow(getnhood(se5), 'InitialMagnification', 'fit')

Using getsequence we can see that there is no decomposition for se5:

numel(getsequence(se5))
ans =

     1

Next time we'll do some timing experiments with the decomposed structuring elements.


Get the MATLAB code

Published with MATLAB® 7.6

2 Responses to “Dilation algorithms—decomposing more shapes”

  1. WS replied on :

    What I don’t understand is, why some decomposed structuring elements are listed twice?

  2. Steve replied on :

    WS—Because they are used twice. Here’s an example: A 1-by-5 flat structuring element can be decomposed into two identical 1-by-3 flat structuring elements.

Leave a Reply

Wrap code fragments inside <pre> tags, like this:

<pre class="code">
a = magic(3);
sum(a)
</pre>

If you have a "<" character in your code, either follow it with a space or replace it with "&lt;" (including the semicolon).


Steve Eddins manages the Image & Geospatial development team at The MathWorks and coauthored Digital Image Processing Using MATLAB. He writes here about image processing concepts, algorithm implementations, and MATLAB.

  • Sana: hi steve, could you explain to me how i would be able to use the dir function, to do a loop through a directory...
  • Nishtha: Sir, I have preprocessed the image in following steps: [1] adaptive histogram equalization [2] thresholding...
  • Kristof: I also strongly support the idea. I have just recently bumped into the problem that im2single was not...
  • Steve: David—I’ m glad you found it useful!
  • David Lalejini: I found your example very useful for finding connected nodes in a large set of input pairs. I start...
  • tommy: Dear Steve, I have a question,please if you are kind to help me regarding the accumulator array dimensions of...
  • Steve: Abc—I don’t know how to distinguish the faces. You might try posting your question in the MATLAB...
  • Manju: well if we have a few ovals within each other like in a cell how do we measure the distance from the center...
  • Steve: Manju—What do you mean? How is each region defined?
  • Manju: if we have 2-3 regions within each other how do we measure the regions of each one?

These postings are the author's and don't necessarily represent the opinions of The MathWorks.