# Co-occurrence matrix

A co-occurrence matrix or co-occurrence distribution is a matrix that is defined over an image to be the distribution of co-occurring pixel values (grayscale values, or colors) at a given offset.

• The offset, ${\displaystyle (\Delta x,\Delta y)}$, is a position operator that can be applied to any pixel in the image (ignoring edge effects): for instance, ${\displaystyle (1,2)}$ could indicate "one down, two right".
• An image with ${\displaystyle p}$ different pixel values will produce a ${\displaystyle p\times p}$ co-occurrence matrix, for the given offset.
• The ${\displaystyle (i,j)^{\text{th}}}$ value of the co-occurrence matrix gives the number of times in the image that the ${\displaystyle i^{\text{th}}}$ and ${\displaystyle j^{\text{th}}}$ pixel values occur in the relation given by the offset.

For an image with ${\displaystyle p}$ different pixel values, the ${\displaystyle p\times p}$ co-occurrence matrix C is defined over an ${\displaystyle n\times m}$ image I, parameterized by an offset ${\displaystyle (\Delta x,\Delta y)}$, as:

${\displaystyle C_{\Delta x,\Delta y}(i,j)=\sum _{x=1}^{n}\sum _{y=1}^{m}{\begin{cases}1,&{\text{if }}I(x,y)=i{\text{ and }}I(x+\Delta x,y+\Delta y)=j\\0,&{\text{otherwise}}\end{cases}}}$

where: ${\displaystyle i}$ and ${\displaystyle j}$ are the pixel values; ${\displaystyle x}$ and ${\displaystyle y}$ are the spatial positions in the image I; the offsets ${\displaystyle (\Delta x,\Delta y)}$ define the spatial relation for which this matrix is calculated; and ${\displaystyle I(x,y)}$ indicates the pixel value at pixel ${\displaystyle (x,y)}$.

The 'value' of the image originally referred to the grayscale value of the specified pixel, but could be anything, from a binary on/off value to 32-bit color and beyond. (Note that 32-bit color will yield a 232 × 232 co-occurrence matrix!)

Co-occurrence matrices can also be parameterized in terms of a distance, ${\displaystyle d}$, and an angle, ${\displaystyle \theta }$, instead of an offset ${\displaystyle (\Delta x,\Delta y)}$.

Any matrix or pair of matrices can be used to generate a co-occurrence matrix, though their most common application has been in measuring texture in images, so the typical definition, as above, assumes that the matrix is an image.

It is also possible to define the matrix across two different images. Such a matrix can then be used for color mapping.

## Aliases

Co-occurrence matrices are also referred to as:

• GLCMs (gray-level co-occurrence matrices)
• GLCHs (gray-level co-occurrence histograms)
• spatial dependence matrices

## Application to image analysis

Whether considering the intensity or grayscale values of the image or various dimensions of color, the co-occurrence matrix can measure the texture of the image. Because co-occurrence matrices are typically large and sparse, various metrics of the matrix are often taken to get a more useful set of features. Features generated using this technique are usually called Haralick features, after Robert Haralick.[1]

Texture analysis is often concerned with detecting aspects of an image that are rotationally invariant. To approximate this, the co-occurrence matrices corresponding to the same relation, but rotated at various regular angles (e.g. 0, 45, 90, and 135 degrees), are often calculated and summed.

Texture measures like the co-occurrence matrix, wavelet transforms, and model fitting have found application in medical image analysis in particular.

## References

1. ^ Robert M Haralick; K Shanmugam; Its'hak Dinstein (1973). "Textural Features for Image Classification" (PDF). IEEE Transactions on Systems, Man, and Cybernetics. SMC-3 (6): 610–621.