# se2off

MainPage

Description: This method returns the array of offsets corresponding to the structuring element Bc.

Signature: off = se2off(Bc)

Input: - Bc: 2 or 3d-array, bool. Boolean array defining the connectivity.

Output:

• off, 2d-array, int32. Array of offsets corresponding to the structuring element Bc.

# Python Implementation

```1 import numpy as np
2
3 def se2off(Bc):
4     Bc2 = Bc.copy()
5     center = np.array(Bc.shape)/2
6     Bc2[tuple(center)] = 0
7     off = np.transpose(Bc2.nonzero()) - center
8     return np.ascontiguousarray(off, dtype = np.int32)
```

# Example

``` 1 import numpy as np
2 from se2off import se2off
3
4
5 Bc = np.ones((3,3), dtype = bool)
6
7 print "2D Structuring element Bc:\n", Bc
8 print
9
10 off = se2off(Bc)
11 print "offsets:\n", off
12 print
13
14 Bc2 = np.ones((3,3,3), dtype = bool)
15 print "3D Structuring element Bc2:\n", Bc2
16 print
17
18 off2 = se2off(Bc2)
19 print "offsets:\n", off2
```
```2D Structuring element Bc:
[[ True  True  True]
[ True  True  True]
[ True  True  True]]

offsets:
[[-1 -1]
[-1  0]
[-1  1]
[ 0 -1]
[ 0  1]
[ 1 -1]
[ 1  0]
[ 1  1]]

3D Structuring element Bc2:
[[[ True  True  True]
[ True  True  True]
[ True  True  True]]

[[ True  True  True]
[ True  True  True]
[ True  True  True]]

[[ True  True  True]
[ True  True  True]
[ True  True  True]]]

offsets:
[[-1 -1 -1]
[-1 -1  0]
[-1 -1  1]
[-1  0 -1]
[-1  0  0]
[-1  0  1]
[-1  1 -1]
[-1  1  0]
[-1  1  1]
[ 0 -1 -1]
[ 0 -1  0]
[ 0 -1  1]
[ 0  0 -1]
[ 0  0  1]
[ 0  1 -1]
[ 0  1  0]
[ 0  1  1]
[ 1 -1 -1]
[ 1 -1  0]
[ 1 -1  1]
[ 1  0 -1]
[ 1  0  0]
[ 1  0  1]
[ 1  1 -1]
[ 1  1  0]
[ 1  1  1]]
```