Why does erosion / expansion of an image using the nulling element cause a (-) value of Inf?

I use imerode and imdilate in matlab with image m

0 0 0 0 1 0 0 0 0 

and structuring element f

 0 

the result for using imerode is

 inf inf inf inf inf inf inf inf inf 

and for imdilate

 -inf -inf -inf -inf -inf -inf -inf -inf -inf 

Can someone explain this to me?
Thank you very much.

+6
source share
3 answers

This artifact occurs when a structuring element is applied on a nonexistent value (for example, it can occur at borders or in your case using a 1x1 structuring element that excludes the center).
In such cases, MATLAB imerode and imdilate give -Inf and Inf respectively.

Here you can read here to clarify this phenomenon.

+1
source

In fact, you do not have a structuring element (SE) equivalent to 0 if that is the result you get. According to your other Erose / Dilate image question with a structuring null element , this is just a misuse of the strel function from Matlab.

First, suppose you actually have SE, which is a unique 0 point. For erosion, this means that you will take the minimum value between the intensity in the current position, which is under control, and only by yourself, so there is nothing more to output than the intensity in the current position. This is the same for dilatation. To verify this, check the correctness of the text describing the formulas for erosion and expansion. And in Matlab:

 f = [0 0 0; 0 1 0; 0 0 0] se = strel('arbitrary', 1, 0) imerode(f, se) ans = 0 0 0 0 1 0 0 0 0 imdilate(f, se) ans = 0 0 0 0 1 0 0 0 0 

Now, if you create an invalid SE, as in se = strel('arbitrary', 0) , and try using morphological operators with it, I can only expect undefined results. Matlab is nice and gives you the opportunity to watch.

0
source

To understand this problem, one must approach the operators of erosion and dilatation. A typical generalization of these operations is local minimum and maximum filters (where the structural element (SE) or the kernel selects the elements to filter).

Explanation of dilatation and erosion with real examples

With SE, which is a 3 × 3 square of true elements, erosion calculates the minimum of each image element by finding the minimum between this element and all its 8 neighbors:

 octave> im im = 5 9 2 6 8 5 8 1 7 8 6 9 8 4 8 1 octave> imerode (im, [1 1 1; 1 1 1; 1 1 1]) ans = 5 2 1 1 5 2 1 1 4 4 1 1 4 4 1 1 

And if you set the central SE element to false, then it calculates the minimum of all its 8 neighbor elements (note that it does not include itself).

 octave> imerode (im, [1 1 1; 1 0 1; 1 1 1]) ans = 5 2 1 1 5 2 1 2 4 4 1 1 4 6 1 6 

But what happens when your SE is “empty” and has no true elements? What if there are no elements from the image that can be used to calculate the minimum? Your use case, SE is only 0 , is very specific in that it has no true element at all. The erosion operation should calculate the minimum of the empty set. What is the minimum value of an empty set?

 octave> imerode (im, [0]) ans = Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf 

The answer does not make much sense. But also the operation, i.e. Minimum empty set. But how does Matlab really get this odd answer Inf ?

How can you get the wrong answer?

The results of Inf and -Inf (which also happens in Octave) are implementation detail. Since Matlab is closed source, we cannot know exactly how they got there, but here is pseudo-code for a possible case (similar to what happens in Octave):

 ## pseudo-code for imerode (local-minimum) that may causes this issue set eroded to image for each element in image set MIN_VAL to +Inf for each value in element neighbourhood if value < MIN_VAL set MIN_VAL to value set eroded[element index] to MIN_VAL 

Is that all? Can we really not calculate erosion and expansion using such an SE?

If you look at the theoretical treatises defining these operations, usually in a continuous interval (instead of discrete), you will find that instead of the maximum and minimum values ​​it refers to supremum and infimum , the result is -Inf and +Inf for empty sets . Therefore, it depends on whether you use the upper and lower limits, and not the maximum and minimum, in your definition of expansion and erosion. And it also depends if you agree that the top and bottom of the empty set are -Inf and +Inf .

Does Matlab Inf and -Inf because of this? I do not know, but I will not. Their documentation on imerode and imdilate refers only to max and min operations, and the most obvious implementation (see Pseudo-code above) leads to these results.

I know that I did not know about this when a few years ago I implemented imdilate and imerode for Octave.

How about this other answer and comments about the meaning of padding?

If your image does not have Inf values, there are two ways they can appear as a result of imdilate and imerode . The end result, Inf values, may look the same, but the reasons why you get them are completely different.

One situation in question is when you have an “empty” SE, that is, an SE without true elements. In this case, at each point in your image, you calculate the mines of the empty set. This has nothing to do with the supplement. No padding and missing value. The reason you get Inf is because you really don't generate the entire set of values, and then find its min. You start with one value ( Inf , the maximum possible), and then compare with the next value that would be in this set. Since this set would be empty, the comparison is never performed and ends with that initial value Inf . He explains this:

 octave> imerode (5, 0) ans = Inf 

Another case that leads to the same result, but has nothing to do with the question, is that SE only “selects” elements outside the image. This is explained on the Mathworks blog. Values ​​of Pad in expansion and erosion . Theoretically, erosion and dilatation operations are ignored from border elements (they should not even exist). In practice, you count them, because ignoring them is expensive computational (since then you need to know where the image is and configure SE accordingly). For example, if your SE is a 3x3 square, and you are evaluating the upper left corner of the image, it is difficult for you to avoid the upper and left elements of the image outside the borders. Therefore, Matlab pads the image using Inf , because these values ​​will not affect the result of the min. But this is only true when there are other values ​​on the set to select min. If at any point in the image all SEs are off-page elements, then you will calculate min from the Inf set, which comes only from the add-on. He explains this:

 octave> imerode (5, [1 1 1; 1 0 1; 1 1 1]) ans = Inf octave> imerode (zeros (3), [0 0 0; 1 0 0; 1 1 0]) ans = 0 0 0 0 0 0 Inf 0 0 octave> imerode (zeros (3), [0 0 0; 0 0 0; 1 1 1]) ans = 0 0 0 0 0 0 Inf Inf Inf 
0
source

All Articles