Moore Neighborhood - Algorithm

Algorithm

The idea behind the formulation of Moore neighborhood is to find the contour of a given graph. This idea was a great challenge for most analysts of the 18th century, and as a result an algorithm was derived from the Moore graph which was later then called the Moore Neighborhood algorithm.

The following is a formal description of the Moore-Neighbor tracing algorithm: Input: A square tessellation, T, containing a connected component P of black cells. Output: A sequence B (b1, b2, ..., bk) of boundary pixels i.e. the contour. Define M(a) to be the Moore neighborhood of pixel a. Let p denote the current boundary pixel. Let c denote the current pixel under consideration i.e. c is in M(p). Let b denote the backtrack of c (i.e. neighbor pixel of p that was previously tested)

Begin Set B to be empty. From bottom to top and left to right scan the cells of T until a black pixel, s, of P is found. Insert s in B. Set the current boundary point p to s i.e. p=s b = the pixel from which s was entered during the image scan. Set c to be the next clockwise pixel (from b) in M(p). While c not equal to s do If c is black insert c in B b = p p = c (backtrack: move the current pixel c to the pixel from which p was entered) c = next clockwise pixel (from b) in M(p). else (advance the current pixel c to the next clockwise pixel in M(p) and update backtrack) b = c c = next clockwise pixel (from b) in M(p). end While End

Read more about this topic:  Moore Neighborhood