Line | |
---|
1 | function mask=dilation(mask,neighboorhood)
|
---|
2 | %deletion algorithm using 4 pixel neighboors.
|
---|
3 |
|
---|
4 | %convolve:
|
---|
5 |
|
---|
6 | matrix=ones(3,3);
|
---|
7 |
|
---|
8 | %4 neighboorhood:
|
---|
9 | %corners
|
---|
10 | if neighboorhood==4,
|
---|
11 | matrix(1,1)=0;
|
---|
12 | matrix(1,3)=0;
|
---|
13 | matrix(3,1)=0;
|
---|
14 | matrix(3,3)=0;
|
---|
15 | end
|
---|
16 | %center
|
---|
17 | matrix(2,2)=0;
|
---|
18 |
|
---|
19 | %convolve mask:
|
---|
20 | mask=filter2(matrix,~mask,'same');
|
---|
21 | pos=find(mask~=0); mask(pos)=1;
|
---|
22 |
|
---|
23 | %opposite to recover the foreground:
|
---|
24 | mask=~mask;
|
---|
Note:
See
TracBrowser
for help on using the repository browser.