There are two different ways to define the neighbors of a pixel located at :
The 4-neighbors of pixel p, denoted by , are the four pixels located at , , , and , there are, respectively, above (north), below (south), to the left (west) and right (east) of the pixel p.
The 8-neighbors of pixel p, denoted by , include the four 4-neighbors and four pixels along the diagonal direction located at (northwest), (northeast), (southwest) and (southeast).