AI Glossary / Computer vision and multimodal AI / Intermediate
Co-occurrence matrix
Definition
A co-occurrence matrix counts how often pairs of values appear together under a specified relationship. In image analysis, a gray-level co-occurrence matrix, or GLCM, counts pairs of pixel brightness levels separated by a chosen distance and direction. It describes aspects of texture that a simple brightness histogram cannot capture.
What it means
Imagine two fabrics containing the same amounts of light and dark material. One has broad stripes; the other has a fine checkerboard. Their brightness histograms might look alike, but neighboring pixels follow different patterns. A co-occurrence matrix records those local pairings. Rows identify the first pixel's brightness category and columns identify its neighbor's category. Large values near the diagonal indicate frequent similar-level pairs for the selected offset. Values farther away indicate pairings with larger brightness differences. The matrix is a statistical description of an image region, not a recognition of the material or an explanation of why its pattern exists.
How it works
First select an image region and convert its intensities into a manageable set of levels. Quantization might group many original brightness values into fewer bins. Next choose an offset, such as one pixel to the right, and inspect every valid pair at that offset. Add one to the matrix cell corresponding to the two levels. Repeat for other offsets if different directions or scales matter.
A normalized matrix divides counts by their total, producing pair frequencies. A symmetric version also treats reversed pair order as equivalent, according to the implementation's convention. Features such as contrast and homogeneity summarize the resulting distribution. Every feature therefore depends on preprocessing, level definitions and offset choices, not just the scene being photographed.
Three practical examples
- A textile inspector compares directional texture measurements from controlled photographs of woven cloth. An unusual measurement can flag a region for inspection without identifying the cause of a defect.
- A materials researcher describes surface texture at several pixel distances. The camera magnification and physical scale must be recorded so that samples remain comparable.
- A document-processing team distinguishes relatively uniform background patches from patterned print. Co-occurrence features can support a classifier, but letters, compression artifacts and scanning noise may produce overlapping measurements.
Think of it this way
Think of a table recording which colored beads sit next to which other beads on a string. Counting individual bead colors misses their arrangement; counting neighboring pairs adds information about that arrangement. The analogy has a limit: an image has many directions and distances, and a pair-count table still loses the exact locations of the pairs. Different images can therefore produce the same matrix.
Worked example
Consider a one-row image with brightness labels [0, 0, 1, 1]. Count ordered pairs one position to the right, without wrapping the last position back to the first. The pairs are (0,0), (0,1) and (1,1). With rows and columns ordered as 0,1, the count matrix is [[1,1],[0,1]]. Dividing by three gives the corresponding pair probabilities.
One common contrast feature sums (i−j)² times each pair probability. Equal-level pairs contribute zero, and the single 0-to-1 pair contributes one-third, so contrast is 1/3. If the same two zeros and two ones are arranged as [0,1,0,1], every adjacent pair differs and contrast becomes 1. Both rows have the same brightness histogram. These values describe this particular offset and quantization; they are not universal texture scores.
Illustrative case study
Fictional example: Brook Loom photographs cloth samples under a fixed lamp and lens setup. Its analyst initially calculates one horizontal GLCM and finds that rotating a sample changes its score. Rather than assuming the software is broken, the team recognizes that the measurement is directional. It records the weave orientation and adds vertical and diagonal measurements. Staff keep the directional results when orientation is meaningful and test an agreed summary when rotation should be ignored. The pilot demonstrates a measurement-design decision; it does not claim that the features automatically detect every weaving fault.
Common misconceptions and mistakes
A co-occurrence matrix is not simply a pixel histogram: it counts relationships between pairs. Normalizing the counts does not remove differences caused by lighting, quantization or image scale. Symmetry does not automatically make the description rotation-invariant. Averaging several directions can reduce directional sensitivity while also discarding useful orientation information. More gray levels are not always better; many bins can create sparse counts in small regions. Finally, a high contrast value is not inherently good or bad. Its meaning depends on the task, selected offset and expected texture.
Business use
Businesses can use these features as compact, inspectable inputs to quality-control or image-search systems. They are attractive when controlled imaging and modest datasets make a simpler approach worth evaluating. Establish a repeatable acquisition procedure, choose physically meaningful region sizes and retain feature settings with each result. Validate on held-out production examples, including benign variation and known defects. Compare the method with simpler baselines and alternative image models. The useful business outcome is a dependable decision process, not merely a spreadsheet containing many texture numbers.
People also ask
Must a co-occurrence matrix describe an image?
No. The general idea applies to paired categories, including words. A GLCM specifically describes spatial relationships between image intensity levels.
Why calculate several matrices for one image?
Different offsets measure relationships at different directions and distances, revealing different aspects of texture.
Does normalization make results comparable?
It removes dependence on the total pair count, but comparable preprocessing, sampling scale and offset definitions are still necessary.
Check your understanding
Two regions have identical brightness histograms. Must their GLCMs be identical?
Answer: No. Histograms count individual brightness levels, whereas GLCMs count spatial pairings. Different arrangements can produce different pair counts despite identical level totals.
Related terms
- Feature extraction
- Contrast
- texture analysis
- image histogram
- quantization
- spatial offset
- image classification
Learn next
Learn image histograms first, then manually count a small GLCM in two directions. Explore how quantization and pixel distance change the counts before studying derived texture features or using them in a classifier.
More in Computer vision and multimodal AI
- Chroma keying - Chroma keying is a compositing technique that separates a subject from a background using color information, commonly from a green or blue screen.
- Circular convolution - Circular convolution combines two finite sequences while treating their indices as periodic, so values that pass one end wrap around to the other.
- Closed-form matting - Closed-form matting is an image-matting method that estimates foreground opacity by constructing and solving a quadratic optimization problem under local...
- Coarse-to-fine alignment - Coarse-to-fine alignment is a method for matching images by estimating their displacement at a reduced resolution and then refining that estimate at...
- Coarse-to-fine warping - Coarse-to-fine warping is a multiscale image-matching procedure that repeatedly transforms one image using a current motion estimate and then estimates the...
- Coded aperture - A coded aperture is a deliberately patterned opening or mask that changes how light reaches an imaging sensor.
Sources
scikit-image, graycomatrix and graycoprops documentation: https://scikit-image.org/docs/stable/api/skimage.feature.html scikit-image, GLCM Texture Features example: https://scikit-image.org/docs/stable/auto_examples/features_detection/plot_glcm.html Official documentation search excerpts consulted; full implementation and editorial review remain pending. Numerical examples and the fictional case are original.
Previous: co-NP-complete Next: Co-occurrence network