8-neighbors of a pixel

The points ND(P) and N4(P) are together known as 8-neighbors of the point P, denoted by N8(P).

Some of the points in the N4, ND and N8 may fall outside image when P lies on the border of image. See the following table :

4-neighbors of a pixel p are its vertical and horizontal neighbors denoted by N4(p)
8-neighbors of a pixel p are its vertical horizontal and 4 diagonal neighbors denoted by N8(p)

Summary is as follows :

ND
N4
ND
N4
P
N4
ND
N4
ND

N4 – 4-neighbors
ND – diagonal neighbors
N8 – 8-neighbors (N4 U ND)