How does 'imerode' function compute erosion with the 'shape' attribute set to 'full'?
9 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
MathWorks Support Team
el 15 de Dic. de 2022
Respondida: MathWorks Support Team
el 31 de En. de 2023
How does 'imerode' function compute erosion when 'shape' attribute is set to 'full'?
As an example, consider the following code:
A = [ 0 1 1 1 0 1 ;...
0 1 1 1 0 1 ;...
1 1 1 1 1 1 ;...
1 1 0 1 1 1 ;...
1 1 0 1 1 1 ];
B = [1 1]; % structuring element
D1 = imerode(A,B,'full');
>> D1 =
0 0 1 1 0 0 1
0 0 1 1 0 0 1
1 1 1 1 1 1 1
1 1 0 0 1 1 1
1 1 0 0 1 1 1
- -
| |
^ ^
The first column The last column should
should all be 0 all be zero
I was expecting the first column and the last column of the output matrix 'D1' to be all zeros, but they contain non-zero elements in the output. Is this behavior expected?
Respuesta aceptada
MathWorks Support Team
el 15 de Dic. de 2022
The values you got are the expected results for “imerode” function.
When computing erosion, “imerode” function follows a “padding and sliding” approach. Since the shape property is set to be “full”, two extra columns are padded to the matrix A (see code below). These two columns are used to process border pixels. The value of these padding pixels varies for dilation and erosion operations. For binary images with erosion operation, these pixels are assumed to be set to 1.
A = [ 0 1 1 1 0 1 ;...
0 1 1 1 0 1 ;...
1 1 1 1 1 1 ;...
1 1 0 1 1 1 ;...
1 1 0 1 1 1 ];
A with padded columns:
A'= [1 0 1 1 1 0 1 1;...
1 0 1 1 1 0 1 1;...
1 1 1 1 1 1 1 1;...
1 1 1 0 1 1 1 1;...
1 1 1 0 1 1 1 1];
^ ^
extra column extra column
B = [1 1]; % structuring element
The erosion process starts with sliding the structuring element across input (Matrix A in this case). For the example you provided, the structuring element is vector B. When input and structuring element overlap, it finds the minimum value of A in the overlapping region.
For pixels at the edge of an image, erosion is computed using the padded columns.
Erosion process for the first row of A
[ 1 0 1 1 1 0 1 1 ]
___ ___
| |
^ ^
Output: 0 0 1 1 0 0 1
_ _
first overlap last overlap output
output is 0 is 1
You can find more information about padding rules following the link below:
0 comentarios
Más respuestas (0)
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!