Let $p$ be a pixel in the image $IH\xd7W$ of $H$ rows and $W$ columns, where $p$ takes gray values in the range $[0,G\u22121]$, $G$ being the range of possible values (256 for an 8-bit image). For instance, if $I$ is an image with five possible gray values from 0 to 4 ($G=5$), as shown in Fig. 1(a), and the parameters $d=1$ and $\theta =45\u2009\u2009deg$ are considered for its CM, then the procedure is as follows. A matrix $CMG\xd7G$ is generated and set to zeros; CM is always square and its dimensions depend on $G$. To assign values to the CM, each pair of pixels in $I$ is analyzed considering the parameters $d$ and $\theta $. Figure 1(b) shows that for the central pixel $p$, the parameters indicate that $q1$ is the neighbor pixel to analyze. Often, the neighborhood analysis is made symmetrically; hence, the cooccurrence is also extended to $q2$. Suppose we want to know the cooccurrences of a gray level $i=1$ (reference level) with a gray level $j$ (comparison level), denoted as $CM(i,j)$. For $j=0$, the cooccurrences with $i$ happen when the coordinates of $p$ are ${I(1,0),I(1,1)}$, therefore $CM(1,0)=2$. For $j=1$, the cooccurrences with $i$ happen in coordinates ${I(2,0),I(2,1)}$ by considering a neighborhood in $q1$. Also, in this case, the cooccurrences happen in a symmetrical way, when $p$ has coordinates ${I(1,1),I(1,2)}$ by considering a neighborhood in $q2$; therefore, $CM(1,1)=4$. The final CM is obtained by analyzing the cooccurrences between all the possible values of $i$ and $j$, as shown in Fig. 1(c) for this example.