1 2nd Project For Data Structure, Shahbahrami Gray-Level Co-Occurrence Matrix
1 2nd Project For Data Structure, Shahbahrami Gray-Level 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
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 .
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).
Ng−1
X
f11 = − px−y (i) log px−y (i) (17)
i=0
HXY − HXY 1
f12 = (18)
max (HX, HY )
where:
Ng Ng
X X
HXY = − pd,θ (i, j) log(pd,θ (i, j)) (20)
i=1 j=1
1/2
f14 = (Second largest eigenvalue of Q) (23)
where
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.
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:
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.
12 1 0 2
1 8 1 0
PH = .
0 1 12 2
2 0 2 16
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
• Symmetrical GLCM:
6 4 0 3
4240
PH = .
0 4 6 3
3038
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
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
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.
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