Function that normalizes a gray-level co-occurrence matrix (GLCM) so that the sum of all the elements equals unity. This has the added benefit of converting the GLCM to a probability distribution.
normalize_glcm(mat)
gray-level co-occurrence matrix
normalized GLCM as a numeric matrix
# normalize an arbitrary matrix
a <- matrix(1:9, nrow = 3)
n_a <- normalize_glcm(a)
print(a)
#> [,1] [,2] [,3]
#> [1,] 1 4 7
#> [2,] 2 5 8
#> [3,] 3 6 9
print(n_a)
#> [,1] [,2] [,3]
#> [1,] 0.02222222 0.08888889 0.1555556
#> [2,] 0.04444444 0.11111111 0.1777778
#> [3,] 0.06666667 0.13333333 0.2000000