An image is denoted by f(x,y) and p,q are used to represent individual pixels of the image. Neighbours of a pixel A pixel p at (x,y) has 4-horizontal/vertical neighbours at (x+1,y), (x-1,y), (x,y+1) and (x,y-1). These are called the 4-neighbours of p : N4(p). A pixel p at (x,y) has 4 diagonal neighbours at…