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.

  • Steve: Kezia—Try imrotate.
  • kezia: steve, how to perform rotation of structuring element by 15 degrees. kindly answer my question. thank u kezia...
  • Steve: Tasha—I only accept comments that are relevant to the particular blog post or are questions or comments...
  • Tasha: Steve,I send you a comment here but still didn’t get any reply yet.I did not see my comment posted here...
  • Steve: Carsten—Thanks for your input.
  • Carsten: Another vote for either imtranslate.m, or at least a blurb in the imtransform help why pure translation...
  • Loren Shure: If you look towards the end of the fftfilt program, you will see that there’s a check to see if...
  • Steve: Sonja—My imwritesize submission on the MATLAB Central File Exchange might be helpful. It was posted...
  • Steve: Grant—Sorry, but it won’t be for R2010a. That development deadline has already passed.
  • Sonja: My publisher is wanting images for a new book to be 300 dpi. Only 5 of the 19 images are 300, the rest are...

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