Misunderstanding of matlab expansion function imdilate() using asymmetric structural elements for gray scale expansion

There are already many other answers to the basic concept. Here we mainly talk about the result of using imdilate() for gray scale expansion when facing irregular structure elements. Here is an easy pitfall to fall into

First define the matrix I to be expanded

>> I=[1 2 3;4 5 6;7 8 9]

I =

     1     2     3
     4     5     6
     7     8     9

If you use ones(3,3) for expansion, the result is obvious, to take the maximum value of the elements in the 3×3 neighborhood

>> se = ones(3)

se =

     1     1     1
     1     1     1
     1     1     1

>> DilatedExpandMaskx = imdilate(I,se)

DilatedExpandMaskx =

     5     6     6
     8     9     9
     8     9     9

This is the case when the structural elements are symmetrical, but what if the structural elements are not?

We can take an asymmetric vector element as a structure to see the result.

>> se = [1 1 0];
>> DilatedExpandMaskx = imdilate(I,se)

DilatedExpandMaskx =

     2     3     3
     5     6     6
     8     9     9

The center of the structural element is 1, the left side is 1, and the right side is 0; it seems that the element at the original position should be compared with the element on the left, and the maximum value should be taken. Then arrange according to the original array, and the result should remain unchanged (I elements are smaller than the element itself), but it can be seen that the result seems to be that the element at the original position is compared with the element at the right position, and the maximum value is taken. Why do you do the opposite?

If the structuring elements are taken as irregular matrices

>> se = ones(3);
>> se(1,1) = 0;
>> se

se =

     0     1     1
     1     1     1
     1     1     1

>> DilatedExpandMaskx = imdilate(I,se)

DilatedExpandMaskx =

     4     5     6
     7     8     9
     8     9     9

It can be seen that the element in the upper left corner is taken as 0, and the element in the lower right corner will not be included when calculating the maximum value in the 3×3 neighborhood. It seems that the structural elements are calculated by placing them on a central symmetry.

The reason for this phenomenon has to go back to the formula. It can be seen from the help documentation of matlab that it is introduced in the gray scale expansion part

What does A(xx', yy') mean? It means that for the element x' = y' = -1 in the upper left corner of se above, it actually traverses I(x+1, y+1), which is the element in the lower right corner of I, when se(-1, -1) = 0, when it does not participate in the operation, it means that the element in the lower right corner of I does not participate in the operation. It seems. The "culprit" lies in the "-" sign in the formula, which seems to make the structural elements symmetrical to the center, and then put them into the original matrix for expansion operations.

At the same time we should note that another sentence in the document,

When "+" is used to define the gray scale expansion, it means that the central symmetry of the structural elements is not required, but directly participates in the expansion operation. The definition of the formula varies from software to software. Of course, in matlab, it has to be the previous situation.

Guess you like

Origin blog.csdn.net/Eason_Y/article/details/129350258