### Neighbors of a Pixel

#### Horizontal and Vertical neighbors

Any pixel p(x, y) has two vertical and two horizontal neighbors, given by :
(x+1, y), (x-1, y), (x, y+1), (x, y-1)

This set of pixels are called the 4-neighbors of P, and is denoted by N4(P). Each of them are at a unit distance from P.In the following image small image, as seen in matlab is shown In this all pixel values are shown :

```>> b

b =

2    2    0    0    2    0    2    0    0    0
1    2    2    1    0    0    0    2    0    0
0    0  253  255  255  254  255  253    0    0
0    1  255  255  252  254  253  255    0    0
0    0  255  255  255  255  255  255    0    0
0    2  253  254  254  255  254  255    0    0
1    0  255  254  255  255  255  254    0    0
0    1  254  255  255  253  255  255    0    0
0    0    0    0    0    0    0    0    0    0
0    0    0    0    0    0    0    0    0    0
```

If we consider pixel value of 1 in pixel(4,2) (4th row and 2nd column). We can say it’s Neighbors are :

```>> b

b =

2    2    0    0    2    0    2    0    0    0
1    2    2    1    0    0    0    2    0    0
0    0  253  255  255  254  255  253    0    0
0    1  255  255  252  254  253  255    0    0
0    0  255  255  255  255  255  255    0    0
0    2  253  254  254  255  254  255    0    0
1    0  255  254  255  255  255  254    0    0
0    1  254  255  255  253  255  255    0    0
0    0    0    0    0    0    0    0    0    0
0    0    0    0    0    0    0    0    0    0

>> b(4,2) % actual value we are targeting

ans =

1

>> b(4,1) % left horizontal neighbor

ans =

0

>> b(4,3) % right horizontal neighbor

ans =

255

>> b(3,2) % above vertical neighbor

ans =

0

>> b(5,2) % below vertical neighbor

ans =

0
```

Neighbors look like this : #### Diagonal neighbors

The four diagonal neighbors of p(x,y) are given by, (x+1, y+1), (x+1, y-1), (x-1, y+1), (x-1 ,y-1). This set is denoted by ND(P).
Each of them are at Euclidean distance of 1.414 from P. They looks like something this : #### Example

```>> b

b =

2    2    0    0    2    0    2    0    0    0
1    2    2    1    0    0    0    2    0    0
0    0  253  255  255  254  255  253    0    0
0    1  255  255  252  254  253  255    0    0
0    1  255  255  255  255  255  255    0    0
0    2  253  254  254  255  254  255    0    0
1    0  255  254  255  255  255  254    0    0
0    1  254  255  255  253  255  255    0    0
0    0    0    0    0    0    0    0    0    0
0    0    0    0    0    0    0    0    0    0

>> b(4,2) % actual value we are targeting

ans =

1

>> b(3,1) % top left diagonal neighbor

ans =

0

>> b(3,3) % top right diagonal neighbor

ans =

253

>> b(5,1) % low left diagonal neighbor

ans =

0

>> b(5,3) % low right diagonal neighbor

ans =

255
```