Definition of the neighbourhood rule (4-/8-neighbours) using Latex tikz (adapted from an example on texample.net)
\begin{tikzpicture}[scale=.6,every node/.style={minimum size=1cm},on grid]
%
\begin{scope}[
yshift=-83,every node/.append style={
yslant=0.5,xslant=-1},yslant=0.5,xslant=-1
]
\draw[step=4mm, black] (0,0) grid (5,5);
\draw[black,very thick] (0,0) rectangle (5,5);
\fill[red] (2.05,2.05) rectangle (2.35,2.35); % center pixel
\fill[blue] (1.65,2.05) rectangle (1.95,2.35); %left
\fill[blue] (2.45,2.05) rectangle (2.75,2.35); % right
\fill[blue] (2.05,2.45) rectangle (2.35,2.75); % top
\fill[blue] (2.05,1.95) rectangle (2.35,1.65); % bottom
% 8 -pixel setting
\fill[blue] (1.65,2.45) rectangle (1.95,2.75); %top-left
\fill[blue] (2.45,2.45) rectangle (2.75,2.75); %top-right
\fill[blue] (2.75,1.95) rectangle (2.45,1.65); %bottom-right
\fill[blue] (1.65,1.95) rectangle (1.95,1.65); %bottom-left
\end{scope}
%
\begin{scope}[
yshift=0,every node/.append style={
yslant=0.5,xslant=-1},yslant=0.5,xslant=-1
]
\fill[white,fill opacity=0.9] (0,0) rectangle (5,5);
\draw[black,very thick] (0,0) rectangle (5,5);
\draw[step=4mm, black] (0,0) grid (5,5);
\fill[red] (2.05,2.05) rectangle (2.35,2.35); %
\fill[red] (2.05,2.05) rectangle (2.35,2.35); % center pixel
\fill[blue] (1.65,2.05) rectangle (1.95,2.35); %left
\fill[blue] (2.45,2.05) rectangle (2.75,2.35); % right
\fill[blue] (2.05,2.45) rectangle (2.35,2.75); % top
\fill[blue] (2.05,1.95) rectangle (2.35,1.65); % bottom
\end{scope}
%
\draw[-latex,thick,gray!70!black](-3,5)node[left]{The center pixel}
to[out=0,in=90] (0,2.2);
%
\draw[-latex,thick,gray!70!black](-3,5)node[left]{ }
to[out=0,in=90] (0,-.8);
%
\draw[thick,gray!70!black](6,4) node {4 neighbourhood rule};
%
\draw[thick,gray!70!black](6,-2) node {8 neighbourhood rule};
%
\end{tikzpicture}