How do I create a structuring element of my own?

조회 수: 2 (최근 30일)
oshawcole
oshawcole 2018년 10월 17일
편집: Matt J 2018년 10월 17일
I want to create a structuring element with the center '0' (eg. [1 0 1])and I want to see the effect of erosion and dilation of it on a 3x3 binary matrix. How do I go about it? please explain. My code is giving me same answers for erosion and dilation.
aa=[1 1 1; 1 0 1; 1 1 1]
s=[1 1 1];
ero=imerode(aa,s)
dil=imdilate(aa,s)
pp=[1 0 1];
ero1=imerode(aa,pp)
dil1=imdilate(aa,pp)
  댓글 수: 2
Matt J
Matt J 2018년 10월 17일
편집: Matt J 2018년 10월 17일
My code is giving me same answers for erosion and dilation.
As it should, for that choice of aa. What do you expect the result to be?
oshawcole
oshawcole 2018년 10월 17일
편집: oshawcole 2018년 10월 17일
Mathematically, the result for aa eroded with s=[1 1 1] should be [0 1 0; 0 0 0; 0 1 0]. For s=[1 0 1]; I was curious as to what happens when I take the center of the structuring element to be 0; so I don't know the answer.

댓글을 달려면 로그인하십시오.

채택된 답변

Matt J
Matt J 2018년 10월 17일
Elements outside the boundary of the matrix do not participate in the erosion/dilation. If you pad aa to a larger size, you will see different effects.
>> aaa=zeros(5); aaa(2:4,2:4)=aa
aaa =
0 0 0 0 0
0 1 1 1 0
0 1 0 1 0
0 1 1 1 0
0 0 0 0 0
>> ero=imerode(aaa,[1,1,1])
ero =
0 0 0 0 0
0 0 1 0 0
0 0 0 0 0
0 0 1 0 0
0 0 0 0 0
>> ero=imerode(aaa,[1,0,1])
ero =
0 0 0 0 0
1 0 1 0 1
1 0 1 0 1
1 0 1 0 1
0 0 0 0 0
>> ero=imdilate(aaa,[1,0,1])
ero =
0 0 0 0 0
1 1 1 1 1
1 0 1 0 1
1 1 1 1 1
0 0 0 0 0
  댓글 수: 2
oshawcole
oshawcole 2018년 10월 17일
Awesome! Can you please explain why is this padding needed? Thank you so much. I really appreciate your help.
Matt J
Matt J 2018년 10월 17일
편집: Matt J 2018년 10월 17일
It is needed so that the code can know that you are assuming zeros lie beyond the boundary of the original 3x3 matrix. Otherwise, it doesn't know what you are assuming.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by