0% found this document useful (0 votes)
64 views11 pages

1 2nd Project For Data Structure, Shahbahrami Gray-Level Co-Occurrence Matrix

The document discusses the Gray-Level Co-occurrence Matrix (GLCM) texture analysis method. The GLCM considers relationships between neighboring pixel pairs in an image. It extracts 14 texture features from the GLCM related to properties like homogeneity, contrast, and complexity. Calculating these GLCM features involves constructing the matrix, extracting probabilities of pixel pairs, and applying equations to measure properties from the normalized matrix. The features can be used for applications like image classification and retrieval.

Uploaded by

gm_farshid
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
64 views11 pages

1 2nd Project For Data Structure, Shahbahrami Gray-Level Co-Occurrence Matrix

The document discusses the Gray-Level Co-occurrence Matrix (GLCM) texture analysis method. The GLCM considers relationships between neighboring pixel pairs in an image. It extracts 14 texture features from the GLCM related to properties like homogeneity, contrast, and complexity. Calculating these GLCM features involves constructing the matrix, extracting probabilities of pixel pairs, and applying equations to measure properties from the normalized matrix. The features can be used for applications like image classification and retrieval.

Uploaded by

gm_farshid
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

1 2nd project for Data Structure, Shahbahrami

Gray-Level Co-occurrence matrix

R. M. Haralick and K. Shanmugam and I. Dinstein


Textural Features for Image Classification
year = 1973, pages = 610-621, month = November, volume = 3, number = 6,
journal = IEEE Transactions on Systems, Man, and Cybernetics
The Gray-Level Co-occurrence Matrix (GLCM) is based on the extraction of
a gray-scale image. It considers the relationship between two neighboring pixels,
the first pixel is known as a reference and the second is known as a neighbor
pixel. The GLCM is a square matrix with Ng dimension, where Ng equals the
number of gray levels in the image. Each element of the matrix is the number of
occurrence of the pair of pixel with value i and a pixels with value j which are
at distance d.
The measuring of texture involves the following steps:

– Make the GLCM symmetrical


– Calculate the probability of each combination, the probability is calculated:

P(i,j,d,θ0 ) = #{((k, l), (m, n)) ∈ (Lr × Lc ) × (Lr × Lc )|


(k − m), (l − n) ∈ {−d, 0, d}|I(k, l) = i, I(m, n) = j, |6 ((k, l), (m, n)) = θ}
(1)
And p(i, j) is the element (i, j)th of the normalized co-occurrence matrix

P(i,j,d,θ0 )
pd,θ (i, j) = PNg PNg (2)
i=1 j=1 P(i,j,d,θ 0 )

If the co-occurrence matrix is symmetric then p(i, j) = (p(i, j) + p(i, j)T )/2
that T indicates the transpose matrix and θ will be 0, 45, 90 and 135.
– Calculated the texture features.
Haralick et al. defined 14 texture features, these features contain the infor-
mation about the image such as homogeneity, contrast, the complexity of
the image, and etc. They are used in many applications such as biological
applications and image retrieval.

This adjacency can occur in four directions based on the angle, horizontal,
vertical, right diagonal, and left diagonal. Figure 1 shows these directions.
The following equations are needed for calculating Haralick texture feature.
Ng
X
px (i) = pd,θ (i, j), (3)
j=1

Ng
X
py (j) = pd,θ (i, j), (4)
i=1
Fig. 1. Diagram of angles, the Haralick texture features are calculated in each of these
directions.

Ng Ng
X X
px+y (k) = pd,θ (i, j), k = {2, 3, ..., 2Ng }, k = i + j, (5)
i=1 j=0

Ng Ng
X X
px−y (k) = pd,θ (i, j), k = {0, 1, ..., Ng }, k = |i − j|. (6)
i=1 j=0

Haralick Texture Features:


With this method, 14 texture features are taken for each image. The features
are as follows:
1. Angular Second Moment (ASM)
ASM also known as uniformity or energy, measures the image homogeneity.
ASM is high when pixels are very similar.
Ng Ng
X X
f1 = pd,θ (i, j)2 . (7)
i=1 j=1

2. Contrast (CON)
Contrast is a measure of intensity or gray-level variations between the ref-
erence pixel and its neighbor. The visual perception is the difference in ap-
pearance of two or more parts of a field seen simultaneously or successively.
PNg −1 2 PNg PNg
f2 = n=0 n { i=1 j=1 pd,θ (i, j)}
(8)
|i − j| = n.
3. Correlation (COR)
Correlation calculates the linear dependency of the gray level values in the co-
occurrence matrix. It shows how the reference pixel is related to its neighbor.
PNg PNg
i=1 j=1 (ij)pd,θ (i, j) − µx µy
f3 = (9)
σx σy
Where:
µx , µy , σx , and σy are the means and standard deviations of px and py .

4. Sum of Squares: Variance


This is a measure of gray tone variance.
Ng Ng
X X
f4 = (i − µ)2 pd,θ (i, j). (10)
i=1 j=1

5. Inverse Difference Moment (IDM)


IDM also sometimes called homogeneity, measures the local homogeneity of
a digital image. IDM returns the measures of the closeness of the distribution
of the GLCM elements to the GLCM diagonal.
Ng Ng
X X 1
f5 = pd,θ (i, j) (11)
i=1 j=1
1 + (i − j)2

6. Sum Average (mean)

2Ng
X
f6 = ipx+y (i) (12)
i=2

7. Sum Variance

2Ng
X
f7 = (i − f8 )2 px+y (i) (13)
i=2

8. Sum Entropy

2Ng
X
f8 = − px+y (i) log px+y (i) (14)
i=2

If the probability equals zero then the log(0) is not defined. To prevent this
problem, it is recommended to use log(p + ε) that ε is an arbitrarily small
positive constant, instead of log(p).
9. Entropy (ENT)
Entropy shows the amount of information of the image that are needed for
image compression.
Ng Ng
X X
f9 = − pd,θ (i, j) log(pd,θ (i, j)) (15)
i=1 j=1

The high entropy image has a great contrast from one pixel to the its neigh-
bor and can not be compressed as a low entropy image which has a low
contrast (a lot of amount of pixels have the same or similar value).

10. Difference Variance

f10 = variance of px−y (16)

11. Difference Entropy

Ng−1
X
f11 = − px−y (i) log px−y (i) (17)
i=0

12. Information Measures of Correlation 1

HXY − HXY 1
f12 = (18)
max (HX, HY )

13. Information Measures of Correlation 2

f13 = (1 − exp[−2.0(HXY @ − HXY )])1/2 (19)

where:
Ng Ng
X X
HXY = − pd,θ (i, j) log(pd,θ (i, j)) (20)
i=1 j=1

HX and HY are entropies of px and py


Ng Ng
X X
HXY 1 = − pd,θ (i, j) log (px (i)py (j)) (21)
i=1 j=1
Ng Ng
X X
HXY 2 = − px (i)py (j) log px (i)py (j) (22)
i=1 j=1

14. Maximal Correlation Coefficient

1/2
f14 = (Second largest eigenvalue of Q) (23)

where

X pd,θ (i, k)pd,θ (j, k)


Q(i, j) = (24)
px(i) py(k)
k

The variance is a measure of the dispersion of the values around the mean,
it is similar to the entropy. It is calculated by these formulas: The complexity of
Haralick for an N × N image is O(N 2 ).
[ rgb]0.00,0.00,1.00Example 3.2: A 4 × 4 image with four gray level values
0 − 3 is assumed.

Fig. 2. An image of size 4 × 4.

Fig. 3. Gray Tone Color


i, j 1 2 3 4
1 ](0, 0) ](0, 1) ](0, 2) ](0, 3)
2 ](1, 0) ](1, 1) ](1, 2) ](1, 3)
3 ](2, 0) ](2, 1) ](2, 2) ](2, 3)
4 ](3, 0) ](3, 1) ](3, 2) ](3, 3)
Table 1. Construction of co-occurrence matrix.

The image is normalized as follows.


 

 0.125 0.125 0.042 0.042 

 
0.042 0.042 0.083 0.083
PH = .

 0.083 0.083 0.000 0.000 

 
0.000 0.000 0.125 0.125

The mean is calculated as follows.

1 ∗ (0.125 + 0.125)
+ 2 ∗ (0.042 + 0.042 + 0.083 + 0.083)
+ 3 ∗ (0.083 + 0.083 (25)
+ 4 ∗ (0.125 + 0.125)
= 1.332

For extracting texture features first the GLCM is calculated. Table 1 depicts
the construction of the GLCM for this example. Each element (i, j) of the matrix
shows the total number of times that two gray tones of element i and j is occurred
based on a function of angle adjacent to each other.
The boundary of distance is calculated:

d((k, l), (m, n)) = max{|k - m|, |l - n|}.

The GLCM and Haralick features can be calculated using two techniques. In
the first technique, the GLCM and Haralick features are calculated for each di-
rection individually, and then textures features of the input image are calculated
based on the features of each direction. In the second technique, the GLCM and
features are calculated for all of directions at the same time.
In the first approach, the GLCM and texture features are calculated for each
direction by assuming that distance (d) is equal to 1.

– Horizontal GLCM ( θ = 0◦ )
½
k - m = 0,
|l - n | = d.
Fig. 4. The symmetrical horizontal GLCM.

• Symmetrical Horizontal GLCM:


Figure 4 shows how the symmetrical horizontal GLCM is calculated.

 

 12 1 0 2 
 
1 8 1 0
PH = .
 0 1 12 2 
 
 
2 0 2 16

• Normalized Symmetrical Horizontal GLCM:


The Normalization of GLCM: Each element of GLCM contains a prob-
ability that is the value of each element divided by the total value of all
of them. The total gray-value is 24.

 

 0.2 0.017 0.000 0.033 
 
0.017 0.133 0.017 0.000
PH = .
 0.000 0.017 0.2 0.033 
 
 
0.033 0.000 0.033 0.267

The ASM is: The ASM is 0.175.


The mean is:
1 ∗ (0.2 + 0.017 + 0.033)
+ 2 ∗ (0.017 + 0.133 + 0.017)
+ 3 ∗ (0.017 + 0.2 + 0.033) (26)
+ 4 ∗ (0.033 + 0.033 + 0.267)
= 3.338
– Right Diagonal GLCM (θ = 45◦ )
½
k - m = d, -d,
|l - n | = -d, d.

• Symmetrical GLCM:
 

 6 4 0 3

 
4240
PH = .
0 4 6 3

 

3038

• Normalized Symmetrical Left Diagonal GLCM:


The total gray-value is 18.

 

 0.12 0.08 0.000 0.06 

 
0.08 0.04 0.08 0.000
N P LD = .

 0.000 0.08 0.12 0.06 
 
0.06 0.000 0.06 0.16

The ASM is:


0.122 + 0.082 + 0.0002 + 0.062
+ 0.082 + 0.042 + 0.082 + 0.0002
+ 0.0002 + 0.082 + 0.122 + 0.062 (27)
+ 0.062 + 0.0002 + 0.062 + 0.162
= 0.096
The mean is:
1 ∗ (0.12 + 0.08 + 0.00 + 0.06)
+ 2 ∗ (0.08 + 0.04 + 0.08 + 0.00)
+ 3 ∗ (0.00 + 0.08 + 0.12 + 0.06) (28)
+ 4 ∗ (0.06 + 0.00 + 0.06 + 0.16)
= 3.12
– Vertical GLCM (θ = 90◦ )
½
k - m = d, -d,
|l - n | = -d, d.

• Symmetrical Vertical GLCM:

 

 0.12 0.08 0.000 0.06 

 
0.08 0.04 0.08 0.000
N P LD = .

 0.000 0.08 0.12 0.06 
 
0.06 0.000 0.06 0.16

 

 660 3  
 
606 0
PV = .
0 6 6 3 
 
 
3 0 3 12
• Normalized Symmetrical Vertical GLCM:
The total gray-value is 24.

 

 0.1 0.1 0.00 0.05 

 
0.1 0.00 0.1 0.00
NPV = .

 0.00 0.1 0.1 0.05 
 
0.05 0.00 0.05 0.2
The ASM is:
0.12 + 0.12 + 0.002 + 0.052
+ 0.12 + 0.002 + 0.12 + 0.002
+ 0.002 + 0.12 + 0.12 + 0.052 (29)
+ 0.052 + 0.002 + 0.052 + 0.22
= 0.11
The mean is:
1 ∗ (0.1 + 0.1 + 0.00 + 0.05)
+ 2 ∗ (0.1 + 0.00 + 0.1 + 0.00)
+ 3 ∗ (0.00 + 0.1 + 0.1 + 0.05) (30)
+ 4 ∗ (0.05 + 0.00 + 0.05 + 0.2)
= 3.2
– Left Diagonal GLCM (θ = 135◦ )
½
k - m = d, -d,
|l - n | = -d, d.

• Symmetrical GLCM:

 

 4 4 1 3

 
4042
P LD = .

 1 4 4 3

 
3238
• Normalized Symmetrical Left Diagonal GLCM:
The total gray-value is 18.

 

 0.08 0.08 0.02 0.06 

 
0.08 0.00 0.08 0.04
P LD = .
 0.02 0.08 0.08 0.06 

 

0.06 0.04 0.06 0.16
The ASM is:
0.082 + 0.082 + 0.022 + 0.062
+ 0.082 + 0.002 + 0.082 + 0.042
+ 0.022 + 0.082 + 0.082 + 0.062 (31)
+ 0.062 + 0.042 + 0.062 + 0.162
= 0.082
The mean is:
1 ∗ (0.08 + 0.08 + 0.02 + 0.06)
+ 2 ∗ (0.08 + 0.00 + 0.08 + 0.04)
+ 3 ∗ (0.02 + 0.08 + 0.08 + 0.06) (32)
+ 4 ∗ (0.06 + 0.04 + 0.06 + 0.16)
= 3.28

In the second technique the GLCM is calculated as follows by assuming d


equals 1 is that:

– Symmetrical GLCM: The GlCM is calculated for four directions

 
 28 9 1 11 

 

15 10 15 2
PT = .
 1 15 28 11 

 

11 2 11 44
– Normalized Symmetrical Left Diagonal GLCM: The total gray-value
is 76.

 

 0.127 0.068 0.005 0.05 
 
0.068 0.045 0.068 0.009
PT = .

 0.005 0.068 0.127 0.05 
 
0.05 0.009 0.05 0.2
The ASM is: The ASM is 0.103 that near sum of all ASMs values of each
directions.
The mean is: The mean is 3.234, with comparing this mean and the average
of means for all angle, we can conclude that the mean of the input image is
the average of means each directions.

[ rgb]0.00,0.00,1.00Example 3.3 : If the image is rotated, the gray-scale view


of image is, Figure 5 shows the gray level of this image.

Fig. 5. 4 × 4 rotated image.

The GLCM matrix is:


– GLCM:

 

 28 15 1 11 

 
15 10 15 2
PH = .
 1 15 28 11 

 

11 2 11 44

– Normalized GLCM:

 

 0.127 0.068 0.005 0.05 
 
0.068 0.045 0.068 0.009
PH = .

 0.005 0.068 0.127 0.05 
 
0.05 0.009 0.05 0.2

The ASM is: The ASM is 0.103.


The mean is: The mean is 3.234

You might also like