MATLAB: How to create a structuring element of the own

structuring element

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 3×3 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)

Best Answer

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