ImageCooccurrence[image,n]
gives the n×n co-occurrence matrix for image.
ImageCooccurrence[image,n,ker]
computes a co-occurrence matrix for arbitrary spatial relationships specified by a kernel ker.
ImageCooccurrence
ImageCooccurrence[image,n]
gives the n×n co-occurrence matrix for image.
ImageCooccurrence[image,n,ker]
computes a co-occurrence matrix for arbitrary spatial relationships specified by a kernel ker.
Details and Options
- ImageCooccurrence[image,n] returns an n×n matrix m whose elements mij represent the probability of all occurrences of a pixel with intensity i to the left or bottom of a pixel with intensity j, assuming all pixels to lie in one of n successive bins.
- With ImageCooccurrence[image,n,ker], the co-occurrence matrix can be computed for arbitrary spatial relationships specified by a matrix ker.
- The default two-dimensional kernel used by ImageCooccurrence is
. - ImageCooccurrence[{image1,image2},…] computes the co-occurrence matrix across two images. The images must have the same dimensions.
- ImageCooccurrence supports a Masking option. The default setting is Masking->All, constructing the co-occurrence matrix based on all of the image pixels.
Examples
open all close allBasic Examples (2)
Scope (4)
Graylevel co-occurrence matrix, computed for a color image:
MatrixPlot[ImageCooccurrence[[image], 16]]Joint histogram of two color channels of the same image:
MatrixPlot[ImageCooccurrence[{[image], [image]}, 16, {{1}}]]Specify a horizontally symmetric kernel:
MatrixPlot[ImageCooccurrence[[image], 32, {{1, 0, 1}}]]Specify a diagonal kernel that matches the pattern of the image:
MatrixPlot[ImageCooccurrence[[image], 32, (| | | |
| - | - | - |
| 1 | 0 | 0 |
| 0 | 0 | 0 |
| 0 | 0 | 0 |)]]Options (1)
Applications (2)
Define a function that computes the Haralick texture contrast measure:
contrast[image_] := Total[Table[(i - j) ^ 2, {i, 256}, {j, 256}] * ImageCooccurrence[image, 256] / 255 ^ 2, 2];Contrast of a checkerboard image and a flat image:
{contrast[[image]], contrast[[image]]}Haralick texture correlation measure for grayscale images:
correlation[image_, ker_] := Module[{miux, mt, m, miuy, stdx, stdy, cm = ImageCooccurrence[image, 256, ker], in = Range[256]}, {m, mt} = Total /@ {cm, Transpose[cm]};
{miuy, miux} = {m.in, mt.in};
{stdy, stdx} = {((in - miuy) ^ 2).m, ((in - miux) ^ 2).mt};
(Total[KroneckerProduct[in, in] * cm, 2] - miux * miuy) / Sqrt[stdx * stdy]]Compute the horizontal correlation:
correlation[[image], {{0, 0, 1}}]correlation[[image], {{0}, {0}, {1}}]Properties & Relations (4)
Co-occurrence matrix of a random image:
ImageCooccurrence[Image[RandomReal[1, {200, 200}]], 16]// MatrixPlotThe total of all elements of the co-occurrence matrix is 1:
Total@Flatten[ImageCooccurrence[[image], 100]]Co-occurrence matrix of a checkerboard image:
ImageCooccurrence[[image], 5] // MatrixFormCo-occurrence matrix of a striped image using a horizontal kernel:
ImageCooccurrence[[image], 5, {{0, 0, 1}}]//MatrixFormRelated Guides
History
Text
Wolfram Research (2010), ImageCooccurrence, Wolfram Language function, https://reference.wolfram.com/language/ref/ImageCooccurrence.html.
CMS
Wolfram Language. 2010. "ImageCooccurrence." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/ImageCooccurrence.html.
APA
Wolfram Language. (2010). ImageCooccurrence. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/ImageCooccurrence.html
BibTeX
@misc{reference.wolfram_2026_imagecooccurrence, author="Wolfram Research", title="{ImageCooccurrence}", year="2010", howpublished="\url{https://reference.wolfram.com/language/ref/ImageCooccurrence.html}", note=[Accessed: 12-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_imagecooccurrence, organization={Wolfram Research}, title={ImageCooccurrence}, year={2010}, url={https://reference.wolfram.com/language/ref/ImageCooccurrence.html}, note=[Accessed: 12-June-2026]}