# graycoprops

Properties of gray-level co-occurrence matrix (GLCM)

## Description

calculates the statistics specified in `stats`

= graycoprops(`glcm`

,`properties`

)`properties`

from the
gray-level co-occurrence matrix `glcm`

.

`graycoprops`

normalizes the gray-level co-occurrence matrix (GLCM) so that
the sum of its elements is equal to 1. Each element
(*r*,*c*) in the normalized GLCM is the joint
probability occurrence of pixel pairs with a defined spatial relationship having
gray level values *r* and *c* in the image.
`graycoprops`

uses the normalized GLCM to calculate
`properties`

.

## Examples

### Calculate Statistics from Gray-level Co-occurrence Matrix

Create simple sample GLCM.

glcm = [0 1 2 3;1 1 2 3;1 0 2 0;0 0 0 3]

`glcm = `*4×4*
0 1 2 3
1 1 2 3
1 0 2 0
0 0 0 3

Calculate statistical properties of the GLCM.

stats = graycoprops(glcm)

`stats = `*struct with fields:*
Contrast: 2.8947
Correlation: 0.0783
Energy: 0.1191
Homogeneity: 0.5658

### Calculate Contrast and Homogeneity from Multiple GLCMs

Read grayscale image into the workspace.

`I = imread('circuit.tif');`

Create two gray-level co-occurrence matrices (GLCM) from the image, specifying different offsets.

`glcm = graycomatrix(I,'Offset',[2 0;0 2])`

glcm = glcm(:,:,1) = 14205 2107 126 0 0 0 0 0 2242 14052 3555 400 0 0 0 0 191 3579 7341 1505 37 0 0 0 0 683 1446 7184 1368 0 0 0 0 7 116 1502 10256 1124 0 0 0 0 0 2 1153 1435 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 glcm(:,:,2) = 13938 2615 204 4 0 0 0 0 2406 14062 3311 630 23 0 0 0 145 3184 7371 1650 133 0 0 0 2 371 1621 6905 1706 0 0 0 0 0 116 1477 9974 1173 0 0 0 0 0 1 1161 1417 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

Get statistics on contrast and homogeneity of the image from the GLCMs.

stats = graycoprops(glcm,{'contrast','homogeneity'})

`stats = `*struct with fields:*
Contrast: [0.3420 0.3567]
Homogeneity: [0.8567 0.8513]

## Input Arguments

`glcm`

— GLCM

matrix of nonnegative integers | array of nonnegative integers

GLCM, specified as one of the following. You can use the `graycomatrix`

function to
create a GLCM.

An

*m*-by-*n*matrix of nonnegative integers for a single GLCMAn

*m*-by-*n*-by-*p*array of nonnegative integers for*p*valid GLCMs.

**Data Types: **`single`

| `double`

| `int8`

| `int16`

| `int32`

| `int64`

| `uint8`

| `uint16`

| `uint32`

| `uint64`

| `logical`

`properties`

— Statistical properties

`"all"`

(default) | comma-separated list of string scalars or character vectors | cell array of string scalars or character vectors | string array | space-separated character vector

Statistical properties of the image derived from GLCM, specified as a
comma-separated list string scalars or character vectors, cell array of
string scalars or character vectors, string array, space-separated character
vector, or `"all"`

. You can specify any of the property
names listed in this table.

Property | Description | Formula |
---|---|---|

| Returns a measure of the intensity contrast between a pixel and its neighbor over the whole image. Range = [0 (size(GLCM,1)-1)^2] Contrast is 0 for a constant image. The property
Contrast is also known as
| $${{\displaystyle \sum _{i,j}\left|i-j\right|}}^{2}p(i,j)$$ |

| Returns a measure of how correlated a pixel is to its neighbor over the whole image.
Correlation is 1 or -1 for a
perfectly positively or negatively correlated image.
Correlation is | $$\sum _{i,j}\frac{(i-\mu i)(j-\mu j)p(i,j)}{{\sigma}_{i}{\sigma}_{j}}$$ |

| Returns the sum of squared elements in the GLCM. Range = [0 1] Energy
is The property Energy is also known as
| $$\sum _{i,j}p{(i,j)}^{2}$$ |

| Returns a value that measures the closeness of the distribution of elements in the GLCM to the GLCM diagonal. Range = [0 1] Homogeneity is 1 for a diagonal GLCM. | $$\sum _{i,j}\frac{p(i,j)}{1+\left|i-j\right|}$$ |

**Example: **`"Contrast","Homogeneity"`

specifies two
properties as a comma-separated list of string scalars

**Example: **`["Contrast","Homogeneity"]`

specifies two
properties as an array of string scalars

**Example: **`{"Contrast","Homogeneity"}`

specifies two
properties as cell array of string scalars

**Example: **`'Contrast Homogeneity'`

specifies two properties
as a space-separated character vector

**Data Types: **`char`

| `string`

| `cell`

## Output Arguments

`stats`

— Statistics derived from GLCM

structure

Statistics derived from the GLCM, returned as a structure with fields that
are specified by `properties`

. Each field contains a
1-by-*p* array, where *p* is the
number of gray-level co-occurrence matrices in `glcm`

.
For example, if `glcm`

is an 8-by-8-by-3 array and
properties is `"Energy"`

, then `stats`

is
a structure containing the field `Energy`

, which contains a
1-by-3 array.

## Version History

**Introduced before R2006a**

## Open Example

You have a modified version of this example. Do you want to open this example with your edits?

## MATLAB Command

You clicked a link that corresponds to this MATLAB command:

Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.

Select a Web Site

Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .

You can also select a web site from the following list:

## How to Get Best Site Performance

Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.

### Americas

- América Latina (Español)
- Canada (English)
- United States (English)

### Europe

- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)

- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)