Skip to Main Content Skip to Search
File Exchange
MATLAB Newsgroup
Link Exchange
  Blogs  
 Contest 
MathWorks.com

Steve on Image Processing

October 23rd, 2006

Nonflat grayscale dilation and erosion

Blog reader Alex asked for an explanation of nonflat grayscale dilation and erosion.

In the most commonly-used form of dilation, the structuring element defines a neighborhood of a pixel. In the output image, a pixel is computed by taking the maximum of all the input pixels in the neighborhood. For erosion, an output image pixel is computed by taking the minimum of all the input pixels in the neighborhood.

In nonflat dilation and erosion, each neighbor has an associated height. A dilation output pixel is computed by first adding the neighbor heights to the neighbor input pixels, and then taking the maximum.

Here's how Digital Image Processing Using MATLAB describes the operation, including the mathematical equation. (This excerpt is from section 9.6.1, pages 366-367.)

"The gray-scale dilation of f by structuring element b [...] is defined as

where D_b is the domain of b, and f(x,y) is assumed equal to [minus infinity] outside the domain of f. This equation implements a process similar to spatial convolution [...]. Conceptually, we can think of rotation the structuring element about its origin and translating it to all locations in the image, just as the convolution kernel is rotated and then translated about the image. At each translated location, the rotated structuring element values are added to the image pixel values and the maximum is computed."

The 'ball' option of the strel function produces a nonflat structuring element.

se = strel('ball',5,5)
 
se =
 
Nonflat STREL object containing 109 neighbors.
Decomposition: 8 STREL objects containing a total of 24 neighbors

Neighborhood:
     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
     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     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     1     1     0
     0     0     1     1     1     1     1     1     1     0     0


Height:
  Columns 1 through 10

      -Inf      -Inf         0    0.6248    1.2497    1.8745    1.2497    0.6248         0      -Inf
      -Inf    0.6248    1.2497    1.8745    2.4994    2.4994    2.4994    1.8745    1.2497    0.6248
         0    1.2497    1.8745    2.4994    3.1242    3.1242    3.1242    2.4994    1.8745    1.2497
    0.6248    1.8745    2.4994    3.1242    3.7491    3.7491    3.7491    3.1242    2.4994    1.8745
    1.2497    2.4994    3.1242    3.7491    4.3739    4.3739    4.3739    3.7491    3.1242    2.4994
    1.8745    2.4994    3.1242    3.7491    4.3739    4.9987    4.3739    3.7491    3.1242    2.4994
    1.2497    2.4994    3.1242    3.7491    4.3739    4.3739    4.3739    3.7491    3.1242    2.4994
    0.6248    1.8745    2.4994    3.1242    3.7491    3.7491    3.7491    3.1242    2.4994    1.8745
         0    1.2497    1.8745    2.4994    3.1242    3.1242    3.1242    2.4994    1.8745    1.2497
      -Inf    0.6248    1.2497    1.8745    2.4994    2.4994    2.4994    1.8745    1.2497    0.6248
      -Inf      -Inf         0    0.6248    1.2497    1.8745    1.2497    0.6248         0      -Inf

  Column 11

      -Inf
      -Inf
         0
    0.6248
    1.2497
    1.8745
    1.2497
    0.6248
         0
      -Inf
      -Inf

 

As far as I know, flat dilation and erosion are far more commonly used. If you know of an image processing application particularly well-suited for applying nonflat dilation and erosion, send me a note - I'd love to hear about it.


Get the MATLAB code

Published with MATLAB® 7.3

9 Responses to “Nonflat grayscale dilation and erosion”

  1. amin replied on :

    Dear steve,
    please can you give me some references available online, about Nonflat grayscale morphological analysis.
    thank you in advance.

  2. Steve replied on :

    Amin - the reference I recommend for morphology is the book by P. Soille, Morphological Image Analysis. Nonflat grayscale dilation and erosion is also covered, briefly, in Digital Image Processing Using MATLAB. As for online references, I have no doubt that Web search engines will lead you to helpful information.

  3. DKS replied on :

    Dear Steve,
    Could you explain why f(x,y) is assumed equal to [minus infinity] outside the domain of f.

    thank you in advance.

  4. Steve replied on :

    DKS - The basic answer is to avoid boundary effects. Specifically, if f(x,y) equals minus infinity outside the image boundaries, then the output of the dilation operation will take on only defined values of f. Perhaps it would have been less surprising if I had said that f(x,y) equals 0 outside the image boundaries. That works fine when image pixels are nonnegative. The key idea is that the assumed value outside the boundary be no greater than any possible image pixel value.

    There is a more detailed treatment of this question in Soille, Morphological Image Analysis: Principles and Applications, 2nd ed. See pages 51, 67, and 73. I’ve made a note to look at this issue again and see whether it’s worth writing more about.

  5. DKS replied on :

    Dear Steve,

    Could you help me on the following?
    What does ( x-x’, y-y’) mean? What happens when x-x’ is negative? in the formula of dilataion

    (f + b)(x,y) = max {f(x-x’,y-y’)+b(x’,y ’)| (x’,y’)belongs to Db}

    Why in dilation it is x-x’ and y-y’, whilst in erosion it is x+x’ and y+y’?

    (f – b)(x,y) = min {f(x+x’,y+y’)+b(x’,y’)| (x’,y’)belongs to Db}

    Please let me know at your earliest convenience. It’s urgent

    Thank you very much.

    DKS

  6. Steve replied on :

    DKS - The notation refers to function f defined on a Cartesian grid, (x,y). (x’,y’) is a point in the domain of the structuring element. For example, if you have a flat, zero-valued structuring element whose domain is -1 < = x' <= 1, -1 <= y' <= 1, then there'll be 9 terms inside the max{} operator: f(x - (-1), y - (-1)), f(x - 0, y - (-1)), ..., f(x - 1, y - 1).

    For any position (x-x’, y-y’) outside the defined domain of f, you have to assume a value for f, or you have to omit those values from the max{} operator. I talked about choosing those “pad” values in my blog last week.

    The choice of equations for dilation and erosion is somewhat a matter of convention. I have the impression that the equations you quoted are more common in the US, whereas a different convention is more often used in Europe. It doesn’t matter that much, except that the choice affects the definition of morphological opening and closing. With the equations you quoted, opening is erosion followed by dilation with the same structuring element. With the European convention, the structuring element has to be reflected for the erosion step.

  7. clcclcclc replied on :

    Recently,I found that some grayscale erosion or dilation using a scaled hemispheric elements.Would you please tell me what the scaled hemispheric elements,and how to use them,thank you very much

  8. Steve replied on :

    clcclcclc—That’s an interesting name that you have. How do you pronounce it?

    I haven’t seen the term scaled hemispheric element before, but I’d guess that it’s the kind of structuring element returned by strel(’ball’, …).

    See the strel doc for more information.

  9. clcclcclc replied on :

    Oh,thank you very much.Recently I saw a paper named
    “FACE DETECTION IN COLOR IMAGES” by Rein-Lien Hsu§, Mohamed Abdel-Mottaleb*, and Anil K. Jain §,in which mentioned that “In our eye detection algorithm, the greyscale dilation and erosion using hemispheric structuring elements at an estimated scale are applied independently to construct EyeMap in the luma”.
    Now I know the algorithm,but I don’t know the structure to be used.
    I am a Chinese student,thank you again for your answer

Leave a Reply


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.

  • Assaf: Hi, I have 3 questions regarding the following sentence: “Rather than using the power spectrum from a...
  • Steve: Cara—I do not understand your question. Can you clarify it?
  • Cara Schiek: Hi. How could I do this same thing with image vales within the patches? cara
  • Steve: Vincent—OK, thanks for the information.
  • Vincent: My only data point on multithreading is that the Performance tab of the Task Manager shows increased CPU...
  • Steve: Vincent—Thanks for giving it a try and reporting back. I’m a bit skeptical that multithreading...
  • Vincent: Oops numbers were wrong. Data set was 450MB large so the numbers are: Results: ImageJ alone =< 5 s (or 90...
  • Vincent: Steve- I just had a quick run at the new imread.m patch. It’s much faster than the previous version...
  • Steve: Erik—Also, separability of the kernel provides no speed benefit in FFT-based implementations....
  • Steve: Erik—Good questions. Remember that, practically speaking, when we filter a 2-D signal with a 1-D filter...

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

Related Topics